Skip to content

Commit 2c9807a

Browse files
committed
Add example with custom checker
1 parent 146b960 commit 2c9807a

File tree

8 files changed

+64
-0
lines changed

8 files changed

+64
-0
lines changed

docs/judge/problem_examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- [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)
55
- [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)
66
- [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)
7+
- [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)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from dmoj.result import CheckerResult
2+
3+
4+
def check(process_output, judge_output, judge_input, point_value, **kwargs):
5+
# process_output contains the user's output
6+
# Firstly, we split the user's output into lines
7+
process_lines = filter(None, process_output.split('\n'))
8+
9+
# We check that they only output 1 line of output
10+
if len(process_lines) != 1:
11+
# They did not follow output specifications
12+
# Thus they get a WA verdict, 0 points, and a message telling them their output is malformed
13+
return CheckerResult(False, 0, "Expected 1 line of output, got %d" % len(process_lines))
14+
15+
# Next we check that they printed only integers
16+
try:
17+
process_tokens = map(int, process_lines[0].split())
18+
except (TypeError, ValueError):
19+
# We again tell them they did not follow output specifications
20+
return CheckerResult(False, 0, "Sequence contains non-numeric values!")
21+
22+
# We check that the sequence has N numbers
23+
24+
# Firstly, we split the input into lines
25+
input_lines = filter(None, judge_input.split('\n'))
26+
# Then we parse N and K from the first line of input
27+
N, K = map(int, input_lines[0].split())
28+
29+
if len(process_tokens) != N:
30+
# We inform them that they did not output N numbers
31+
return CheckerResult(False, 0, "Sequence's length is incorrect!")
32+
33+
# We check all numbers in the sequence are non-negative
34+
if any(process_token < 0 for process_token in process_tokens):
35+
# We again tell them they did not follow output specifications
36+
return CheckerResult(False, 0, "Sequence contains negative numbers!")
37+
38+
# We check that the sequence sums to K
39+
conditions_met = 0
40+
41+
if sum(process_tokens) == K:
42+
conditions_met += 1
43+
else:
44+
return CheckerResult(False, 0, "Sequence's sum is incorrect!")
45+
46+
# The minimal possible product is 0, so we check if there exists a 0 in the sequence
47+
if not all(process_tokens):
48+
conditions_met += 1
49+
50+
# Finally, return the verdict
51+
return CheckerResult(True, point_value * conditions_met / 2.0)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 926
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1002 243013241
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34124 10
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5 100000000
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
checker: check.py
2+
test_cases:
3+
- {in: in1.txt, points: 20}
4+
- {in: in2.txt, points: 20}
5+
- {in: in3.txt, points: 20}
6+
- {in: in4.txt, points: 20}
7+
- {in: in5.txt, points: 20}

0 commit comments

Comments
 (0)