Skip to content

Commit 1907a3b

Browse files
committed
Add example with custom checker
1 parent 146b960 commit 1907a3b

File tree

8 files changed

+63
-0
lines changed

8 files changed

+63
-0
lines changed

docs/judge/problem_examples.md

+1
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)
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 is of the correct length
23+
# Firstly, we split the input into lines
24+
input_lines = filter(None, judge_input.split('\n'))
25+
# Then we parse N and K from the first line of input
26+
N, K = map(int, input_lines[0].split())
27+
28+
if len(process_tokens) != N:
29+
# We inform them that they did not output N numbers
30+
return CheckerResult(False, 0, "Sequence's length is incorrect!")
31+
32+
# We check all numbers in the sequence are non-negative
33+
if any(process_token < 0 for process_token in process_tokens):
34+
# We again tell them they did not follow output specifications
35+
return CheckerResult(False, 0, "Sequence contains negative numbers!")
36+
37+
# We check that the sequence sums to K
38+
conditions_met = 0
39+
40+
if sum(process_tokens) == K:
41+
conditions_met += 1
42+
else:
43+
return CheckerResult(False, 0, "Sequence's sum is incorrect!")
44+
45+
# The minimal possible product is 0, so we check if there exists a 0 in the sequence
46+
if not all(process_tokens):
47+
conditions_met += 1
48+
49+
# Finally, return the verdict
50+
return CheckerResult(True, point_value * conditions_met / 2.0)

problem_examples/checker/seq3/in1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 926

problem_examples/checker/seq3/in2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1002 243013241

problem_examples/checker/seq3/in3.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
34124 10

problem_examples/checker/seq3/in4.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5 100000000

problem_examples/checker/seq3/in5.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2 1
+7
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)