Competitive Programming

IOI 2021

All 6 IOI tasks from 2021, organized as individual solution pages.

6 problem pages
6 editorials
6 C++ solutions
May 21, 2026 most recently updated solution

Problem set

Each entry below goes straight to the public problem page, with the statement, editorial, code, and raw resources kept together.

IOI 2021

Candies

There are n boxes, each with capacity c[i]. There are q operations, where operation j adds v[j] candies to all boxes in range [l[j], r[j]]. If v[j] > 0, candies are added (capped at capacity). If v[j] < 0, candies are...

TeX C++
Open problem page
IOI 2021

DNA

Given two strings a and b of equal length over the alphabet \ A, T, C\, answer queries: for a given substring range [l, r], what is the minimum number of swaps to transform a[l..r] into b[l..r]? If impossible, return -1.

TeX C++
Open problem page
IOI 2021

Dungeons

There are n dungeons (indexed 0 to n-1) and a final dungeon n. Each dungeon i has: s[i]: opponent strength p[i]: strength gain if you lose w[i]: next dungeon if you win (w[i] > i) l[i]: next dungeon if you lose If you...

TeX C++
Open problem page
IOI 2021

Keys

Given n rooms and m bidirectional corridors. Each room i contains a key of type r[i]. Each corridor j connects rooms u[j] and v[j] and requires a key of type c[j] to traverse. Starting from room i, you pick up the key...

TeX C++
Open problem page
IOI 2021

Parks

There are n fountains at positions (x[i], y[i]) where all coordinates are even. Two fountains are adjacent if they differ by exactly 2 in one coordinate and are equal in the other. Build roads between adjacent fountai...

TeX C++
Open problem page
IOI 2021

Registers

You have m = 100 registers, each containing b = 2000 bits. Register 0 initially contains n values, each k bits wide, packed consecutively. The remaining bits are 0. You must output the sorted values (or just the minim...

TeX C++
Open problem page