Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 63 ยท Getting Started with Contests

What Is Competitive Programming?

Learn what competitive programming is: contest formats like ICPC, IOI, Codeforces and AtCoder, how judges grade code, how ratings work, and how to train well.

Competitive programming is a sport for your problem-solving brain. You get a set of problems written in plain language, a clock, and a programming language of your choice. Your job is to turn each statement into a program that prints the right answer for every hidden test, and to do it both correctly and fast. A website called a judge runs your program, compares its output with the expected output, and tells you immediately whether you passed.

This tutorial teaches the skills that make that possible: reading statements quickly, picking the right idea, writing short and correct code, and debugging under pressure. We use Python throughout, because it is easy to read and every example here runs live in your browser. If you want the underlying data structures first, the DSA tutorial covers them in depth; here we focus on how to use them in contests.

How a contest works

Every contest follows the same loop.

  1. You read a problem. It has a story, an exact description of the input and output, limits on the input size, and one or more small sample tests.
  2. You write a program that reads the input from standard input and writes the answer to standard output.
  3. You submit it. The judge compiles or starts it, feeds it many hidden tests, and checks each answer under a time limit and a memory limit.
  4. You get a verdict. Only a fully correct program counts as solved.
flowchart LR
    A["Read statement"] --> B["Find idea<br/>and check limits"]
    B --> C["Write code"]
    C --> D["Test samples<br/>and own cases"]
    D --> E["Submit"]
    E --> F{"Verdict"}
    F -->|"Accepted"| G["Next problem"]
    F -->|"Rejected"| H["Debug"]
    H --> C

The contest loop: the faster you cycle through it with fewer wrong submissions, the better you rank.

Verdicts

A judge answers with a short code. You will see these constantly, and the next lessons teach you to fix each one. The full story is in Verdicts and Debugging.

Verdict Meaning
Accepted (AC) Every test passed within the limits.
Wrong Answer (WA) Your output differs from the expected output on some test.
Time Limit Exceeded (TLE) Your program was too slow on some test.
Memory Limit Exceeded (MLE) Your program used more memory than allowed.
Runtime Error (RE) Your program crashed: an exception, a bad index, deep recursion.
Presentation Error (PE) The answer is right but the formatting is not (used by some judges).
Compilation Error (CE) The code could not be compiled or parsed at all.

Notice that the judge does not give you the failing test in most contests. Learning to guess why you failed is a core skill.

Famous formats

Contests differ in how they score and who they are for.

  • ICPC style. Teams of three share one computer and solve as many problems as possible in about five hours. Ranking is by the number of problems solved, then by penalty time: the sum of the minutes at which each problem was solved, plus a fixed penalty (typically 20 minutes) for every rejected submission on a problem you eventually solved. You will build an ICPC scoreboard later.
  • IOI style. The International Olympiad in Informatics is for secondary-school students. Problems have subtasks worth partial points, so a slower solution can still earn something.
  • Codeforces rounds. Typically two hours and five to seven problems of rising difficulty. Points for a problem shrink as time passes, and you get a rating that changes after every round. Many rounds also let you hack: submit a test that breaks another contestant's solution.
  • AtCoder. Short, clean statements and mathematically flavoured problems. Beginner contests (ABC) run weekly with eight problems and a clear difficulty ladder.
  • LeetCode contests. Four problems in 90 minutes, usually in function form rather than reading from standard input. They resemble interviews more than the formats above.
  • Practice sites. CSES, Kattis, SPOJ, and many others host problem archives you can solve at any time with no clock.

You do not need to enter any of them to benefit. Solving archived problems with a self-imposed timer is excellent training.

Ratings

Most online platforms give you a number that estimates your strength. After each contest it goes up if you did better than the system expected and down if you did worse. The usual model is Elo-like: it predicts the probability that you beat another contestant from the difference in ratings.

The core formula is small enough to run. With ratings ra and rb, the expected score of player A against player B is 1 / (1 + 10 ** ((rb - ra) / 400)).

Python Expected score from a rating gap

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A 400-point advantage means roughly a 91 percent expected win rate. Real platforms add many details, such as rating uncertainty for new accounts, but the idea is exactly this. In the rating project you will build a full calculator.

How it differs from interviews and from DSA study

These three things overlap but are not the same.

Interview preparation Studying DSA Competitive programming
Goal Show clear thinking to a person Understand structures and algorithms Solve unseen problems correctly and fast
Input Usually a function argument Whatever the lesson uses Standard input, often huge
Judging A human reads your code and your reasoning You judge yourself A machine runs hidden tests with strict limits
Style Readable, well explained Teaching code Short, fast to write, exactly correct
Difficulty Moderate Gradual Rises steeply; the hardest problems need new ideas

Learning data structures is the foundation, and competitive programming is where you practise choosing and combining them against a stopwatch. The hardest part is often not coding but realising which known tool a disguised problem needs.

Why bother

People take it up for different reasons: sharper thinking, better interview results, a path to the ICPC or the IOI, or simply because solving a hard problem feels great. The skills transfer. You learn to estimate costs before writing code, to find edge cases, to test with a brute force, and to read a precise specification, all of which matter in real engineering.

A training mindset

A few habits separate people who improve from people who stall.

  • Solve problems just above your level. If you solve everything instantly you are not learning, and if you solve nothing you are not either. Aim for problems you solve about half the time.
  • Upsolve. After a contest, return to every problem you did not finish and solve it, reading hints or editorials only after a real attempt. Most of the growth happens here.
  • Think before you type. A correct plan takes minutes; debugging a wrong plan takes much longer.
  • Keep a log. Note the problems you failed and why (missed idea, edge case, slow code). Patterns in the log show what to study next. The training plan tracker project turns this into a tool.
  • Be consistent. An hour a day beats a weekend marathon.
  • Do not memorise solutions. Memorise ideas and the situations they apply to.

The following snippet imitates a judge in miniature. It runs a function on tests, compares outputs, and reports a verdict in the same style as the real thing. It is a toy, but it shows what happens to your program on every submission.

Python A toy judge

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The off-by-one version fails at the first test, the crashing version passes the first two and then throws on n = 10, and only the correct one is accepted. In a real contest the hidden tests include tiny cases, huge cases and nasty special cases, so passing the sample proves very little.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a judge do when you submit a solution?

    Judges are automatic. They run your program on many hidden tests and check each answer against the limits, which is why samples alone prove little.
  2. 2. In ICPC-style ranking, which comes first when comparing two teams?

    Teams are ranked by problems solved first. Penalty time only breaks ties between teams with the same count.
  3. 3. Your program prints the correct answers but the judge says Time Limit Exceeded. What does that tell you?

    TLE only concerns speed. The logic may well be right, but the algorithm is too slow for the largest inputs.
  4. 4. Which habit helps most to improve over months?

    Upsolving turns each failure into learning. Memorised solutions do not transfer to new problems, and trivial problems do not stretch you.

Summary

  • Competitive programming means solving precisely stated problems with code that a judge grades automatically on hidden tests, under time and memory limits.
  • Verdicts such as AC, WA, TLE, MLE and RE tell you the category of failure, not the cause.
  • Popular formats include ICPC (team, penalty time), IOI (subtasks), Codeforces and AtCoder (rated rounds), and LeetCode contests (function style).
  • Ratings follow an Elo-like model: the bigger your advantage, the higher your expected score.
  • It differs from interview prep and from DSA study: input is standard input, grading is a machine, and speed and exactness both count.
  • Train just above your level, upsolve every contest, think before typing, and keep a log of mistakes.

Next: Reading a Problem Statement