-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example with custom checker #46
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from dmoj.result import CheckerResult | ||
|
||
|
||
def check(process_output, judge_output, judge_input, point_value, **kwargs): | ||
# process_output contains the user's output | ||
# Firstly, we split the user's output into lines | ||
process_lines = filter(None, process_output.split('\n')) | ||
|
||
# We check that they only output 1 line of output | ||
if len(process_lines) != 1: | ||
# They did not follow output specifications | ||
# Thus they get a WA verdict, 0 points, and a message telling them their output is malformed | ||
return CheckerResult(False, 0, "Expected 1 line of output, got %d" % len(process_lines)) | ||
|
||
# Next we check that they printed only integers | ||
try: | ||
process_tokens = map(int, process_lines[0].split()) | ||
except (TypeError, ValueError): | ||
# We again tell them they did not follow output specifications | ||
return CheckerResult(False, 0, "Sequence contains non-numeric values!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quote |
||
|
||
# We check that the sequence is of the correct length | ||
# Firstly, we split the input into lines | ||
input_lines = filter(None, judge_input.split('\n')) | ||
# Then we parse N and K from the first line of input | ||
N, K = map(int, input_lines[0].split()) | ||
|
||
if len(process_tokens) != N: | ||
# We inform them that they did not output N numbers | ||
return CheckerResult(False, 0, "Sequence's length is incorrect!") | ||
# We check all numbers in the sequence are non-negative | ||
if any(process_token < 0 for process_token in process_tokens): | ||
# We again tell them they did not follow output specifications | ||
return CheckerResult(False, 0, "Sequence contains negative numbers!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single quote |
||
|
||
# We check that the sequence sums to K | ||
conditions_met = 0 | ||
|
||
if sum(process_tokens) == K: | ||
conditions_met += 1 | ||
else: | ||
return CheckerResult(False, 0, "Sequence's sum is incorrect!") | ||
# The minimal possible product is 0, so we check if there exists a 0 in the sequence | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: new line before this. |
||
if not all(process_tokens): | ||
conditions_met += 1 | ||
|
||
# Finally, return the verdict | ||
return CheckerResult(True, point_value * conditions_met / 2.0) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 926 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1002 243013241 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
34124 10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
5 100000000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
checker: check.py | ||
test_cases: | ||
- {in: in1.txt, points: 20} | ||
- {in: in2.txt, points: 20} | ||
- {in: in3.txt, points: 20} | ||
- {in: in4.txt, points: 20} | ||
- {in: in5.txt, points: 20} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes and an f-string.