Stage 1 · Lesson 1 of 8
Reading constraints and time limits
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
- CourseFreeLearnCpp.com
LearnCpp.com · Beginner
Free and thorough: read the chapters on vectors, references, lambdas and the standard library if C++ is new to you
- BookFreeCompetitive Programmer's Handbook
Antti Laaksonen · Beginner
Chapter 1 covers C++ for contests, input and output and working with numbers; Chapter 2 covers complexity
Practise
Keep handy
Also worth your time
A clear walk through time and space complexity, the language you need to read constraints
- USACO GuideGo deeper
The General section has practical pages on choosing a language, fast input and output and debugging