How to Learn Competitive Programming: The Complete 2027 Roadmap
A free, rating-by-rating path from your first Codeforces problem to Expert and beyond: which language to use, what topics to learn in what order, the best free books and problem sets, how to practice and upsolve, contest strategy, and tested Python templates you can copy.
Last reviewed: December 2026
If you want to know how to learn competitive programming (CP) and actually improve your rating instead of grinding random problems, this guide gives you a staged roadmap with time estimates, the best free resources (CSES, USACO Guide, CP-Algorithms, AtCoder, Codeforces), and a practice system that works. It suits high-school olympiad students (USACO, IOI), university students aiming for ICPC, and developers who want sharper algorithmic problem solving for interviews.
This repository also includes small, tested code templates in templates/ (Python building blocks with unit tests and a C++ starter file).
Table of Contents
- What Competitive Programming Is
- Is It Worth It in the AI Era?
- Choosing a Language
- The Roadmap at a Glance
- Stage 0: Prerequisites
- Stage 1: Implementation and Basics
- Stage 2: Core Techniques
- Stage 3: Graphs and Dynamic Programming
- Stage 4: Data Structures and Math
- Stage 5: Advanced Topics
- Where to Practice: Judges Compared
- Best Free Books and Guides
- YouTube Channels
- How to Practice Effectively
- Contest Strategy
- Debugging and Stress Testing
- Competitions to Aim For
- Using the Templates in This Repo
- Common Mistakes
- FAQ
- Where to Go Next
- Contributing
What Competitive Programming Is
Competitive programming is solving well-defined algorithmic problems under time pressure. Each problem gives you an input format, an output format and limits (typically around 1-2 seconds and 256 MB). You submit code to an online judge, which runs it on hidden tests and returns a verdict:
| Verdict | Meaning | Usual cause |
|---|---|---|
| AC | Accepted | You solved it |
| WA | Wrong Answer | Logic bug, edge case, overflow |
| TLE | Time Limit Exceeded | Algorithm too slow, or slow I/O |
| MLE | Memory Limit Exceeded | Arrays too big, recursion storing too much |
| RE | Runtime Error | Index out of range, division by zero, stack overflow |
| CE | Compilation Error | Wrong language version or a typo |
Contests are rated: on Codeforces your rating moves after each rated round and maps to a colored rank (Newbie, Pupil, Specialist, Expert, Candidate Master, Master and up). AtCoder uses its own rating and color system.
A rule of thumb for complexity: judges execute roughly 10^8 simple operations per second in C++ (much less in Python). So:
| n up to | Acceptable complexity |
|---|---|
| 10-12 | O(n!) or O(2^n · n) |
| 20-25 | O(2^n) |
| 500 | O(n^3) |
| 5,000 | O(n^2) |
| 2 · 10^5 to 10^6 | O(n log n) or O(n) |
| 10^9 and above | O(log n), O(sqrt n) or a formula |
Read the constraints first. They tell you which algorithm the setter intends.
Is It Worth It in the AI Era?
In September 2025, AI systems from OpenAI and Google DeepMind reached gold-medal-level results on the ICPC World Finals problem set, with OpenAI’s system reported to solve all 12 problems and Gemini 10. So why learn CP?
- The thinking transfers. Breaking a problem down, proving an approach, choosing the right data structure and reasoning about complexity is exactly what you need to review and direct AI-generated code.
- Interviews still test it. Technical interviews at many companies are built on the same patterns (graphs, DP, binary search).
- Olympiads and ICPC still run. They open doors to universities, scholarships and teams.
- It is fun. It is a mental sport, and like chess, it stays worthwhile after machines beat humans.
Rules matter: Codeforces published a rule restricting AI use in rated rounds (latest revision we found: September 2024). In short: code-completion style help for syntax is allowed, but using AI to solve problems during a rated contest is not. Outside contests, AI is fine for learning, for example to explain an editorial. Always check each platform’s current rules.
Choosing a Language
| Language | Speed on judges | Pros | Cons | Verdict |
|---|---|---|---|---|
| C++ | Fastest | STL (sort, priority_queue, set/map), nearly every editorial and library uses it, required for top-level performance | Undefined behavior, harder to debug | Best pick for serious CP |
| Python | Slow (often 10-50x slower) | Fast to write, big integers built in | TLE on heavy problems; recursion limits | Great to start and for easy/medium problems; switch to C++ later |
| Java / Kotlin | Fast enough | Safe, good collections; Kotlin is popular on Codeforces | Verbose (Java), slower I/O unless careful | Fine choice if you already know it |
| Rust | Fast | Safe and fast | Slower to write under time pressure | Niche, but supported on major judges |
Best pick: If you already know Python, start with it and learn C++ when you reach stage 3 or keep hitting TLE. Use cppreference as your STL reference. If you are aiming at IOI, note that IOI tasks are typically solved in C++.
The Roadmap at a Glance
Time estimates assume 7-10 hours per week. Ratings are rough Codeforces equivalents and vary a lot between people.
| Stage | Focus | Time | Rough target rating | Main resources |
|---|---|---|---|---|
| 0 | One language, basic syntax, complexity | 2-4 weeks | Unrated | Language tutorial, AtCoder Beginners Selection |
| 1 | Implementation, sorting, simulation, greedy basics | 1-2 months | 800-1200 | CSES Introductory, AtCoder ABC A-C |
| 2 | Binary search, two pointers, prefix sums, bit tricks, basic math | 2-3 months | 1200-1400 | CSES Sorting & Searching, USACO Guide Silver |
| 3 | Graphs (BFS/DFS/shortest paths/DSU) and DP | 3-4 months | 1400-1700 | CSES Graph & DP sections, AtCoder Educational DP Contest |
| 4 | Segment trees, Fenwick trees, number theory, combinatorics | 3-4 months | 1700-1900 | CSES Range Queries & Math, CP-Algorithms |
| 5 | Advanced: strings, trees (LCA, HLD), flows, advanced DP, geometry | Ongoing | 1900+ | USACO Guide Platinum/Advanced, CP-Algorithms, Codeforces EDU |
The most important factor is volume of thoughtful practice plus upsolving, not the number of topics you have “covered”.
Stage 0: Prerequisites
Time: 2-4 weeks
- Variables, loops, conditionals, functions, arrays/lists, strings, maps/dictionaries.
- Reading input and printing output exactly as specified.
- Big-O notation and the table above.
- Integer overflow: in C++, use
long longwhenever values can exceed about 2 · 10^9.
Practice: AtCoder Beginners Selection (10 short warm-up problems) and the first problems of the CSES Problem Set.
Stage 1: Implementation and Basics
Time: 1-2 months. Goal: solve easy problems quickly and without bugs.
Topics:
- Simulation and careful implementation (read the statement twice).
- Sorting with custom comparators.
- Frequency counting with arrays and hash maps.
- Simple greedy ideas (and testing them with counterexamples).
- Brute force with loops; complete search over small inputs.
- Strings: reversing, palindromes, counting characters.
Practice:
- CSES Problem Set Introductory Problems.
- AtCoder Beginner Contests (problems A-C), from the contest archive.
- Codeforces problemset filtered to rating 800-1100.
Milestone: you solve Div. 2/Div. 3 problem A reliably within 10 minutes.
Stage 2: Core Techniques
Time: 2-3 months.
| Technique | Key idea | Reference |
|---|---|---|
| Prefix sums / difference arrays | O(1) range sums after O(n) preprocessing | USACO Guide Silver |
| Binary search (including on the answer) | Monotone predicate, find first true | CP-Algorithms: binary search |
| Two pointers / sliding window | Move two indices monotonically | CSES Sorting & Searching |
| Sorting + greedy | Exchange arguments to prove greedy | Competitive Programmer’s Handbook ch. 6 |
| Bit manipulation | Masks, subsets, XOR tricks | Handbook ch. 10 |
| Recursion and backtracking | Generate subsets, permutations | Handbook ch. 5 |
| Basic number theory | GCD, primes, divisors, modular arithmetic | Sieve of Eratosthenes |
| STL / standard containers | set, map, priority queue, deque | cppreference |
Milestone: Div. 2 A-B consistently, sometimes C. Roughly Pupil to Specialist.
Stage 3: Graphs and Dynamic Programming
Time: 3-4 months. This is where most people’s rating jumps.
Graphs
- Representations: adjacency lists, grids as graphs.
- BFS (shortest paths in unweighted graphs, multi-source BFS) and DFS (components, cycle detection).
- Topological sort; DAG DP.
- Shortest paths: Dijkstra, Bellman-Ford, Floyd-Warshall.
- Disjoint Set Union and minimum spanning trees (Kruskal, Prim).
- Trees: DFS order, subtree sizes, diameter, rerooting basics.
Dynamic programming
- Define the state, the transition, the base case, the order of computation. Start with the CP-Algorithms intro to DP.
- Classic families: knapsack, LIS, LCS, grid paths, intervals, bitmask DP, digit DP, DP on trees.
- Do the AtCoder Educational DP Contest: 26 problems from basic to hard, all classic patterns. This is the single best DP practice set.
- Then the CSES Dynamic Programming section.
Milestone: Div. 2 C regularly. Around Specialist to Expert.
Stage 4: Data Structures and Math
Time: 3-4 months.
| Topic | What to learn |
|---|---|
| Fenwick tree | Point update, prefix query; counting inversions |
| Segment tree | Range queries, point updates, then lazy propagation |
| Sparse table | O(1) range min on static arrays |
| Coordinate compression | Map big values to small indices |
| Modular arithmetic | Fast exponentiation, modular inverse, factorials, nCr |
| Combinatorics | Counting, inclusion-exclusion, stars and bars |
| Number theory | Sieve variants, prime factorization, Euler’s totient |
| Probability and expected value | Linearity of expectation |
| Strings | Prefix function (KMP), Z-function, hashing |
Use the AtCoder Library (ACL) for reference implementations once you understand how they work. The AtCoder Library Practice Contest has one problem per ACL component.
Milestone: Div. 2 D sometimes. Expert to Candidate Master range.
Stage 5: Advanced Topics
Time: ongoing.
- Trees: LCA (binary lifting), Euler tour + segment tree, heavy-light decomposition, centroid decomposition, small-to-large merging.
- Graphs: strongly connected components, bridges and articulation points, 2-SAT, max flow / min cut, bipartite matching.
- DP optimizations: convex hull trick, divide and conquer DP, SOS DP, Knuth.
- Strings: suffix arrays, Aho-Corasick, Manacher.
- Math: FFT/NTT, matrix exponentiation, Möbius inversion, game theory (Sprague-Grundy).
- Geometry: cross products, convex hull, line intersection.
- Square root decomposition and Mo’s algorithm.
Resources: USACO Guide Gold, Platinum and Advanced sections; CP-Algorithms; the Codeforces EDU section (free interactive lessons with practice); KACTL, KTH’s ICPC team notebook, for well-tested advanced implementations.
Where to Practice: Judges Compared
| Platform | Best for | Contest frequency | Notes |
|---|---|---|---|
| Codeforces | Rated contests, huge problem archive with difficulty ratings and tags | Several per week | Best pick for main contest practice; editorials after each round |
| AtCoder | Clean, high-quality problems; ABC weekly for beginners-intermediate | Weekly (ABC), plus ARC/AGC | Best pick for beginners; very clear statements |
| CSES Problem Set | A curated set of ~300+ classic problems by topic | No contests | Best pick for structured topic practice |
| USACO Guide | Curated modules with problems from many judges | No contests | Built for USACO, excellent for anyone |
| Kattis | ICPC-style problems | Occasional | Many past ICPC regionals |
| CodeChef | Weekly Starters contests | Weekly | Large community in South Asia |
| LeetCode | Interview-style problems; weekly contests | Weekly | Easier than CF on average; better for interviews |
| Project Euler | Math-heavy problems | No contests | Great for number theory |
| CodinGame | Bot and optimization games | Periodic | Different flavor, fun |
Helpful extras: AtCoder Problems (tracks your AtCoder progress and difficulty estimates) and CLIST (contest calendar across judges).
Best Free Books and Guides
All of these are legally free from their authors or maintainers.
| Resource | Level | Why it is great |
|---|---|---|
| Competitive Programmer’s Handbook by Antti Laaksonen | Beginner-Intermediate | Best pick. Concise, covers stages 1-5, pairs with CSES |
| USACO Guide | All levels | Modules from Bronze to Advanced with curated problems and solutions |
| CP-Algorithms | Intermediate-Advanced | Reference articles for almost every standard algorithm |
| Algorithms by Jeff Erickson | University level | Free textbook with excellent DP and graph chapters |
| MIT 6.006 Introduction to Algorithms | University level | Lectures and notes for theory foundations |
| VisuAlgo | Beginner | Animations of data structures and algorithms |
| OI Wiki | All levels | Huge Chinese-language wiki; use a translator if needed |
Paid books: Competitive Programming 4 by Steven and Felix Halim (cpbook.net, paid) is a thorough reference with a large problem list. Guide to Competitive Programming by Antti Laaksonen (Springer, paid) is the expanded print successor to the handbook.
YouTube Channels
| Channel | Good for |
|---|---|
| Errichto | Clear lectures and contest walkthroughs |
| William Lin | Live contest screencasts and practice advice |
| SecondThread | Contest solutions and algorithm explanations |
| Colin Galen | Mindset, practice strategy, problem solving |
| pashka | Problem analysis by an ICPC coach |
| NeetCode | Interview-style problems (LeetCode focus) |
Watching others solve problems is useful only after you have tried the problem yourself.
How to Practice Effectively
The core loop
- Pick problems slightly above your level. On Codeforces, about your rating to your rating + 200-300.
- Think first, code second. Write the idea and complexity down before typing.
- Time-box. Give a problem 30-60 minutes of real effort (less when starting). If stuck, read the first hint or the first line of the editorial only, then continue.
- Upsolve. After every contest, solve at least the next problem you could not solve. This is the highest-value habit in CP.
- Write a short note for every problem that taught you something: the key observation in one or two sentences.
- Review notes weekly. Patterns repeat across problems.
Weekly plan (about 8-10 hours)
| Day | Activity |
|---|---|
| Mon | Topic study (1 chapter or USACO Guide module) + 2 problems |
| Tue | 3 problems from the current topic |
| Wed | Virtual contest or rated round |
| Thu | Upsolve the contest |
| Fri | 2 problems above your level |
| Weekend | One rated contest (Codeforces or AtCoder ABC) + upsolving |
Practice sets by goal
| Goal | Set |
|---|---|
| First 100 problems | CSES Introductory + Sorting & Searching; AtCoder ABC A-C |
| Learn DP | AtCoder Educational DP Contest, then CSES DP |
| Learn graphs | CSES Graph Algorithms, USACO Guide Silver/Gold graph modules |
| Range queries | CSES Range Queries, Codeforces EDU segment tree course |
| ICPC team prep | Past regionals on Kattis and Codeforces Gym |
The USACO Guide’s own advice on practicing is worth reading.
Contest Strategy
- Read all problem statements early, at least the first few. Problems are usually but not always ordered by difficulty.
- Check constraints first. They hint at the intended complexity.
- Test on the samples and your own edge cases before submitting: n = 1, all equal values, maximum values, negative numbers, empty strings.
- Penalties matter. On Codeforces, wrong submissions cost points; on AtCoder, penalty time. Spend 30 seconds checking before you submit.
- Skip and return. If a problem is not clicking after 20-30 minutes, read the next one.
- Do not panic about rating drops. Ratings fluctuate; long-term trend is what counts.
- Virtual contests (Codeforces lets you replay past contests) are excellent practice under real time pressure.
Debugging and Stress Testing
Most WA verdicts come from edge cases. When you cannot find the bug:
- Re-read the statement. Check output format, 1-indexed vs 0-indexed, multiple test cases.
- Check overflow (
long long), uninitialized variables, and arrays reset between test cases. - Stress test: write a slow brute-force solution, a random small-input generator, and a script that compares both outputs until they differ. The smallest failing input usually shows the bug immediately.
# stress.sh (sketch): gen.py prints a random small test, brute.py is obviously correct
for i in $(seq 1 1000); do
python3 gen.py $i > in.txt
python3 sol.py < in.txt > out1.txt
python3 brute.py < in.txt > out2.txt
cmp -s out1.txt out2.txt || { echo "Mismatch on seed $i"; cat in.txt; break; }
done
- In C++, compile locally with warnings and sanitizers:
g++ -std=c++17 -O2 -Wall -Wextra -fsanitize=address,undefined.
Competitions to Aim For
| Competition | Who | Format | Link |
|---|---|---|---|
| USACO | Pre-university students (open to all) | Online, Bronze → Silver → Gold → Platinum divisions | usaco.org |
| IOI | High-school students via national olympiads | Two contest days, individual | ioinformatics.org |
| ICPC | University teams of three, one computer | Regionals → World Finals | icpc.global |
| Codeforces rated rounds | Anyone | Div. 1-4, Educational, Global rounds | codeforces.com |
| AtCoder | Anyone | ABC (beginner), ARC (regular), AGC (grand) | atcoder.jp |
| Meta Hacker Cup | Anyone | Annual online rounds | Announced on Meta’s Coding Competitions page |
Google’s Code Jam, Kick Start and Hash Code were discontinued in 2023, so ignore older advice that centers on them. The 2026 ICPC World Finals were scheduled for Dubai in November 2026; check icpc.global for results and next year’s schedule.
Using the Templates in This Repo
| File | Contents |
|---|---|
templates/cp.py |
Fast input, DSU, Fenwick tree, segment tree, sieve, modular inverse and nCr, binary search on the answer, Dijkstra, KMP prefix function, LIS |
templates/template.cpp |
Minimal C++17 contest starter (fast I/O, multi-test loop) |
tests/test_cp.py |
Unit tests, including randomized comparisons against brute force |
Run the tests with only the Python standard library:
python3 -m unittest discover -s tests -v
The C++ starter uses <bits/stdc++.h>, which is available on GCC (what Codeforces, AtCoder and most judges use) but not with Apple’s default clang on macOS. On a Mac, install GCC via Homebrew or replace the include with the specific standard headers you need.
Understand before you copy. Templates save typing; they do not replace knowing why the code works. Re-implement each structure yourself at least once.
Common Mistakes
- Learning advanced topics too early. Most problems below 1600 need clever observations, not segment trees.
- Not upsolving. Solving only what you already can teaches little.
- Reading editorials too fast. Struggle productively first; then read partial hints.
- Random problem grinding. Mix topic practice with contests.
- Ignoring overflow and multi-test resets.
- Rating obsession. Measure problems solved above your level and consistency instead.
- Burnout. Short daily sessions beat occasional marathons.
FAQ
How long does it take to get good at competitive programming?
Highly variable. Many people reach Codeforces Specialist (1400) in 6-12 months of steady practice and Expert (1600) in 1-2 years. Some move faster with strong math backgrounds; consistency matters more than talent.
Is C++ required?
No, but it helps a lot past the intermediate level because of speed and because most editorials use it. Python is fine to learn concepts and for easier problems.
Does competitive programming help with coding interviews?
Yes, considerably. Interview problems are usually easier than mid-level contest problems, but you will need to practice explaining your thinking out loud, which contests do not train.
How much math do I need?
At the start, very little: arithmetic, basic logic and some counting. Number theory, combinatorics and probability become important around 1600+.
Codeforces or LeetCode?
Codeforces (and AtCoder) for competitive programming; LeetCode for interview preparation. They overlap but optimize for different things.
What should I do when I am stuck on a problem?
Try small examples by hand, look for a pattern, consider the constraints, try to simplify the problem. After a time box, read one hint, not the full solution.
Am I too old to start?
No. Many people start in university or later. Olympiads have age limits, but online contests do not.
Can I use AI to practice?
Outside rated contests, yes: asking an AI to explain an editorial or review your approach can speed up learning. During rated contests, follow each platform’s rules; Codeforces restricts AI use for solving problems.
What is upsolving?
Solving the problems you could not solve during a contest afterwards, with help from the editorial if needed. It is how most improvement happens.
Where to Go Next
- Finish the CSES Problem Set and the USACO Guide up to Gold, then Platinum.
- Join or form an ICPC team; practice team contests on Codeforces Gym.
- Contribute problems: preparing problems teaches you even more than solving them.
- Explore algorithm engineering and optimization contests (AtCoder Heuristic Contest).
- Use your skills for interviews: practice explaining solutions aloud.
Contributing
Contributions are welcome: fixes, better explanations, more tested templates (please include unit tests that compare against a brute-force solution), and high-quality free resources. Do not add copied editorial text, paid content or pirated books.
If this helped you, a star helps others find it.
License
Code and text in this repository are released under the MIT License.
More free resources
Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.