๐ WAYPOINT LESSON
A Taxonomy of Wrong Answers
โญโญโญ advancedโณ 25 min read๐ Lesson 262 of 281
The twelve failure classes that eat contest points, with the symptom each one shows and the first probe to run.
A Taxonomy of Wrong Answers
When a submission fails, the verdict narrows the search space. Map verdict โ likely class โ cheapest probe:
WA (wrong answer) families
- Integer overflow โ
intused where sums/products reach 2^31. Probe: the largest single test. Fix:long long(and remember1LL *in mixed expressions). - Greedy missing an exchange argument โ passes sorted-ish samples, dies on adversarial orderings. Probe: n = 2 or 3 with equal values. Fix: prove the swap, or switch to DP.
- Wrong DP transition/order โ loop order violates dependency. Probe: hand-run the smallest input where a later state feeds an earlier one.
- Boundary bug โ
l..rvsl..r-1,<vs<=, 0-index vs 1-index. Probe: n = 1, and the first/last element alone. - Wrong graph assumption โ assuming a tree/DAG/connected when the statement doesn't. Probe: a 2-cycle, a disconnected pair.
- Uninitialized / stale state โ reused buffer, forgot to reset between test groups. Probe: run the "same test" twice in a row mentally.
TLE families
- Wrong complexity โ O(nยฒ) where O(n log n) is required. Probe: the max-n test. Fix: the structures of earlier courses.
- Hidden constant โ cin/cout without sync off, clearing a vector per query, string concatenation in a loop.
- Worst-case structure โ quicksort-style recursion on sorted input, hash maps attacked by adversarial keys.
RE / MLE families
- Recursion depth โ DFS on a 2ยท10^5-chain blows the stack. Fix: iterative DFS or explicit stack (the harness has run binary-searched recursion limits โ assume ~10^5 is unsafe).
- Array too small / index out of bounds โ off-by-one in allocation. Probe: exactly the boundary index.
- Precision โ doubles compared with
==, accumulating error over 10^6 additions. Fix: integers where possible; else epsilon with care.
The clinic exercises below each hide exactly one of these. Your job in every one: (1) find the counterexample input, (2) name the class, (3) fix the code, (4) verify the fix against the counterexample.