Skip to content

Commit

Permalink
Add example with custom checker
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritofeng committed Dec 17, 2018
1 parent 146b960 commit 46d2925
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 0 deletions.
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)
57 changes: 57 additions & 0 deletions problem_examples/checker/seq3/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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!")
else:
# We check that the sequence has N numbers

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

# 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

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}

0 comments on commit 46d2925

Please sign in to comment.