|
| 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) |
0 commit comments