Competitive programming

Stage 1 of 10 · 8 lessons · ~3 weeks

C++ for contests

Set up a compiler and a template, learn the STL containers and algorithms contests use every day, and learn to read constraints so you know what complexity you can afford.

Start: Reading constraints and time limits

Lessons· one lesson for each topic, in this order

  1. 1Reading constraints and time limits
  2. 2Compiler, editor and flags
  3. 3Your template and fast input and output
  4. 4Vectors, pairs and sorting
  5. 5Sets, maps and priority queues
  6. 6STL algorithms you will use weekly
  7. 7Integer overflow and choosing types
  8. 8Hash maps and anti-hash tests

Do this

  • Install g++ and an editor, and compile a program with warnings and with sanitizers.
  • Write your contest template and type it from memory three times.
  • Solve the first 10 CSES Introductory Problems in C++.
  • Make an account on Codeforces and on AtCoder.
  • Solve 10 problems rated 800 on Codeforces, reading the constraints first each time.
  • Keep every accepted solution in a Git repository, one folder per platform.

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

Before moving on: A compiler and editor set up with warnings and sanitizers, a template you can type from memory, and the first two CSES sections or 20 easy Codeforces problems solved in C++.

Tauseef's advice
You do not need all of C++ for contests. Vectors, pairs, sort, set, map, priority_queue and a handful of algorithms cover most problems for a long time. Learn those properly, keep your template short, and spend the rest of your time solving problems.

Mark this stage as not done?