Skip to main content
πŸ“œ WAYPOINT LESSON

How to Read a Contest Problem

⭐ beginner⏳ 14 min readπŸ“ Lesson 1 of 281

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

  1. What exactly is being asked? (one number? a line? several?)
  2. Read the data types: what is the largest possible value?
  3. What happens at the smallest input?
  4. 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.