Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/judge/problem_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- [Interactive Grading (conditional IO-based)](https://github.com/DMOJ/docs/tree/master/problem_examples/interactive/seed2) - implements [https://dmoj.ca/problem/seed2](https://dmoj.ca/problem/seed2)
- [Signature Grading (IOI-style)](https://github.com/DMOJ/docs/tree/master/problem_examples/signature/siggrade) - implements [https://dmoj.ca/problem/siggrade](https://dmoj.ca/problem/siggrade)
- [Generating IO Data on the Fly (large testcase generation)](https://github.com/DMOJ/docs/tree/master/problem_examples/generator/ds3) - implements [https://dmoj.ca/problem/ds3](https://dmoj.ca/problem/ds3)
- [Custom Checker (IO-based)](https://github.com/DMOJ/docs/tree/master/problem_examples/checker/seq3) - implements [https://dmoj.ca/problem/seq3](https://dmoj.ca/problem/seq3)
48 changes: 48 additions & 0 deletions problem_examples/checker/seq3/check.py
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))
Copy link
Contributor

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.


# 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!")
Copy link
Contributor

Choose a reason for hiding this comment

The 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!")
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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)
1 change: 1 addition & 0 deletions problem_examples/checker/seq3/in1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 926
1 change: 1 addition & 0 deletions problem_examples/checker/seq3/in2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1002 243013241
1 change: 1 addition & 0 deletions problem_examples/checker/seq3/in3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
34124 10
1 change: 1 addition & 0 deletions problem_examples/checker/seq3/in4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 100000000
1 change: 1 addition & 0 deletions problem_examples/checker/seq3/in5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 1
7 changes: 7 additions & 0 deletions problem_examples/checker/seq3/init.yml
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}