Learn › Competitive programming intro

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:

  1. You choose a problem.
  2. You read the input/output format, constraints, and examples.
  3. You write a complete program in an allowed language.
  4. The judge compiles/runs it against many tests.
  5. 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

Read limits before designing
  1. n <= 20 — Exponential subset search may be possible because 2^20 is about one million.
  2. n <= 2,000 — O(n^2) can often pass; O(n^3) is usually risky.
  3. n <= 100,000 — You usually need O(n), O(n log n), or close to it.
  4. 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

Next: C to C++ bridge

More in Competitive programming intro