Programs and expressions 0/5

Lesson 3 of 21

Reading input and the judge

Read a problem's input, print its answer, and check the program against the samples, the limits and the judge's verdicts.

Part 1 of 6 Tests and the judge

Tests and the judge

The Train or taxi program started with the line n, a, b = map(int, input().split()), and we said we would take it apart. We will do that in this lesson, after a look at why a program reads its numbers at all instead of having them written into the code. The reason is that a judge runs your program on many different inputs.

When you submit a program to a judge such as AtCoder or Codeforces, nobody reads what it prints. Instead, the judge runs your program on a series of tests. Each test is an input with the correct output stored next to it. The judge gives your program the input and compares what it prints with the stored output.

Say you are solving a typical first problem: you are given two integers AA and BB, and you print A×BA \times B. The problem never tells you which two integers. A program that just prints 10 would pass the test whose input is 2 5 and fail every other test, so your program has to read the numbers from its input.

The steps of one test

Here is what happens on one test of that problem, with the input 2 5:

The judge repeats these steps for every test
StepWhat happens
1The judge starts your program and sends it the input 2 5, as if someone had typed it.
2The program reads the two numbers and computes 2×52 \times 5.
3The program prints 10.
4The judge compares 10 with the correct output, 10. They match, so the test passes.

Your submission is accepted only if it passes every test, and AtCoder shows that as AC, for accepted. If the output is different on any test, you get WA, for wrong answer. The problem statement shows you a few of the tests, called the samples. The rest are hidden, so most of the tests your program runs on are ones you never see.