What competitive programming is
How online judges work, what Accepted means, and why constraints force algorithm choices. · 8 min read
Concept
Competitive programming is algorithmic problem solving under a strict contract: read a statement, write a program, submit it to an online judge, and get a verdict. The judge runs your code on visible samples and hidden tests. You do not explain your idea to the judge; your program either produces exactly the required output for every case or it does not.
This is why CP is useful for learning algorithms. It makes the feedback loop honest. A solution that is elegant but too slow gets TLE. A solution that passes the samples but misses an edge case gets WA. A solution with the right idea but wrong integer type can still fail. The constraints are not decoration; they are the map to the intended complexity.
The judge loop
Most online judges follow the same flow:
- You choose a problem.
- You read the input/output format, constraints, and examples.
- You write a complete program in an allowed language.
- The judge compiles/runs it against many tests.
- You receive a verdict such as AC, WA, TLE, MLE, RE, or CE.
What makes CP different from normal exercises
In a textbook exercise, the hard part is often proving the algorithm. In CP, the hard part is the whole chain: noticing the pattern, choosing data structures, bounding the complexity, translating the idea into bug-resistant code, and handling input exactly. The judge is strict because real software is strict too.
A good CP attempt is not 'I started coding quickly.' It is usually:
- Restate the task in one sentence.
- Identify input sizes and value ranges.
- List edge cases before coding.
- Choose the target complexity.
- Write the simplest program that meets that bound.
- Test samples, then make adversarial custom tests.
Constraints decide the algorithm
n <= 20— Exponential subset search may be possible because 2^20 is about one million.n <= 2,000— O(n^2) can often pass; O(n^3) is usually risky.n <= 100,000— You usually need O(n), O(n log n), or close to it.n <= 1,000,000— Linear or near-linear work, careful memory, and fast I/O start to matter.
Result: Constraints are the first clue to the intended complexity