Competitive programming

Stage 1 · Lesson 1 of 7

Reading constraints and time limits

C++ for contests

Every problem gives limits, such as n up to 2 * 10^5, and a , usually one or two seconds. A judge runs very roughly 10^8 simple operations per second, so the limit tells you the complexity to aim for before you think about the story.

O(n^2) is fine for n = 5,000 but far too slow for 2 * 10^5, where you need O(n log n). Big-O notation describes how the work grows with n. Tiny limits, such as n up to 20, hint at trying every subset. Read the constraints first, then the statement.

Common trapdesigning a clever solution, coding it for twenty minutes and only then noticing it is a factor of n too slow for the limits.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CourseFree
    LearnCpp.com

    LearnCpp.com · Beginner

    Free and thorough: read the chapters on vectors, references, lambdas and the standard library if C++ is new to you

  • BookFree
    Competitive Programmer's Handbook

    Antti Laaksonen · Beginner

    Chapter 1 covers C++ for contests, input and output and working with numbers; Chapter 2 covers complexity

Practise

  • Start with the Introductory Problems section: short tasks that exercise loops, strings and the STL

  • Filter the problem set to rating 800 and solve a few each day to get used to contest input and output

Keep handy

  • Keep it open for exact signatures and complexities of vector, set, map, sort and lower_bound

Also worth your time

Mark this stage as not done?