diff --git a/docs/judge/problem_examples.md b/docs/judge/problem_examples.md index 4f621eb..d008c16 100644 --- a/docs/judge/problem_examples.md +++ b/docs/judge/problem_examples.md @@ -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) diff --git a/problem_examples/checker/seq3/check.py b/problem_examples/checker/seq3/check.py new file mode 100644 index 0000000..935a88c --- /dev/null +++ b/problem_examples/checker/seq3/check.py @@ -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!") + + # 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!") + + # 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) diff --git a/problem_examples/checker/seq3/in1.txt b/problem_examples/checker/seq3/in1.txt new file mode 100644 index 0000000..1c1c386 --- /dev/null +++ b/problem_examples/checker/seq3/in1.txt @@ -0,0 +1 @@ +2 926 diff --git a/problem_examples/checker/seq3/in2.txt b/problem_examples/checker/seq3/in2.txt new file mode 100644 index 0000000..35fa60f --- /dev/null +++ b/problem_examples/checker/seq3/in2.txt @@ -0,0 +1 @@ +1002 243013241 diff --git a/problem_examples/checker/seq3/in3.txt b/problem_examples/checker/seq3/in3.txt new file mode 100644 index 0000000..35de1ce --- /dev/null +++ b/problem_examples/checker/seq3/in3.txt @@ -0,0 +1 @@ +34124 10 diff --git a/problem_examples/checker/seq3/in4.txt b/problem_examples/checker/seq3/in4.txt new file mode 100644 index 0000000..70950fb --- /dev/null +++ b/problem_examples/checker/seq3/in4.txt @@ -0,0 +1 @@ +5 100000000 diff --git a/problem_examples/checker/seq3/in5.txt b/problem_examples/checker/seq3/in5.txt new file mode 100644 index 0000000..cba3471 --- /dev/null +++ b/problem_examples/checker/seq3/in5.txt @@ -0,0 +1 @@ +2 1 diff --git a/problem_examples/checker/seq3/init.yml b/problem_examples/checker/seq3/init.yml new file mode 100644 index 0000000..7f2a1eb --- /dev/null +++ b/problem_examples/checker/seq3/init.yml @@ -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}