Competitive Programming

IOI 2018

All 6 IOI tasks from 2018, 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 2018

Combo

A secret string S of length n is composed of characters from \ A, B, X, Y\. The function press(p) returns the length of the longest common prefix of S and the string p. Determine S using at most n+2 calls to press.

TeX C++
Open problem page
IOI 2018

Highway Tolls

We are given a connected undirected graph with N vertices and M edges. Two hidden vertices s t were chosen. For each query we assign every edge weight A or B (A < B), and the grader returns the shortest-path distance...

TeX C++
Open problem page
IOI 2018

Mechanical Doll

Build a switching network of binary switches (Y-shaped connectors called ``switches'') to route a ball through a sequence of triggers A_1, A_2,, A_m in order. Each switch has two outputs (X and Y) and alternates betwe...

TeX C++
Open problem page
IOI 2018

Meetings

There are n mountains with heights H_0,, H_ n-1. For a query (L, R), choose a meeting point m [L, R] to minimize: cost(m) = _ i=L ^ R _ j [ (i,m), (i,m)] H_j. Return the minimum cost.

TeX C++
Open problem page
IOI 2018

Seats

An H W grid has seats numbered 0 to N-1 (N = HW), each at a unique cell. A prefix \ 0, 1,, k-1\ is ``rectangular'' if these seats occupy a contiguous rectangular subgrid. After each swap of two seats, count the number...

TeX C++
Open problem page
IOI 2018

Werewolf

For each query (S,E,L,R), determine whether there exists a vertex T such that: S can reach T using only vertices with index at least L; E can reach T using only vertices with index at most R. This is exactly the condi...

TeX C++
Open problem page