How to Read a Contest Problem
Statement, input/output format, constraints, examples β and the checklist to run before writing code.
Reading a real contest problem
A standard HSG problem has five blocks:
PROBLEM: Sum of two numbers
DESCRIPTION: Given two integers a, b. Print their sum.
INPUT: One line with two integers a and b (a, b β€ 10^18).
OUTPUT: Print a + b.
EXAMPLE: (sample input β sample output)
CONSTRAINTS: 30% of tests have a, b β€ 10^9; 100% have a, b β€ 10^18.
Input/Output is your contract with the judge: wrong format, a missing space, a missing newline = wrong answer even with a correct algorithm. Constraints are the biggest hint of all: they tell you which algorithm is fast enough (next module).
The pre-keyboard checklist
- What exactly is being asked? (one number? a line? several?)
- Read the data types: what is the largest possible value?
- What happens at the smallest input?
- Are there subtasks? Which points can a simple solution earn?
Judge verdicts
| Verdict | Meaning | | --- | --- | | Accepted | All tests passed | | Wrong Answer | It ran, but the output is wrong | | Time Limit Exceeded | Too slow β the algorithm itself must change | | Runtime Error | It crashed (division by zero, bad index, stack overflowβ¦) | | Compile Error | It never compiled |
This course's convention
You write void solve(istream& in, ostream& out) β read from in as if
it were cin, write to out as if it were cout. The system calls
solve(cin, cout) for you β exactly what a contest judge does with your
program.