Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IMO 2025 Q6

Q6: Consider a 2025×2025 grid of unit squares. Matilda wishes to place on the grid some rectangular tiles, possibly of different sizes, such that each side of every tile lies on a grid line and every unit square is covered by at most one tile.

Determine the minimum number of tiles Matilda needs to place so that each row and each column of the grid has exactly one unit square that is not covered by any tile.

This is an interesting problem with a surprising solution. It's also an easy problem to understand and think about in your head (though certainly not easy to solve!). I have an interactive visualization at https://charleslow.github.io/grid_visualization to explore this problem.

Initial Attempt

The first instinct is to take an approach like below. That is, we observe that using single row / column rectangular tiles is sufficient to tile the grid. Hence the solution uses tiles if the grid is . It's instead of because of the gaps (black squares) up against the grid boundaries. I thought this was the solution initially, and tried to prove it but failed.

Naive 4-tile configuration
Figure: A naive approach.

My Solution

Let's draw a vertical and horizontal line from each uncovered square (call it a "gap"). Observe there may be 2-4 such lines emanating in the NSEW directions from each gap. Overall, there would be such lines ( because there is no line at the first & last row / column). Let's call each of these lines a "half-line".

Since each row, col pair has one gap, we are assured that a tiling that covers all the half-lines satisfies Matilda (as it will then cover every row and column, except for the gaps).

Now the question is, how quickly can we cover the half-lines with a minimal number of tiles? In other words, how many half-lines can we clear with each tile we introduce?

Now, it is tricky to analyze the number of lines we clear on each turn, because it depends on the preceding steps. For example, if we had cleared all but one remaining tile on each half-line (show example), then the next step can clear a large number of half-lines. It is hard to reason across multiple turns.

So an important observation:

Lemma 1: The number of gaps that each tile touches is an upper bound for the number of half-lines cleared after steps.

Proof. This is quite self-explanatory, as touching a gap is pre-requisite to clearing a half-line that emanates from that side of the gap.

Lemma 1 shifts the analysis from clearing half-lines to analyzing (and maximizing) the number of gaps we touch with every tile we introduce. The number of gaps touched per tile is easier to reason about, as we shall see. We will make the upper bound an equality later on with a specific strategy.

Lemma 2: The number of gaps touched per tile is capped at 4.

Proof. This is also not hard to see. Imagine a tile bounded on all sides by gaps. Since there can only be one gap per row and column, the tile cannot be touching more than one gap per side. Since the tile only has 4 sides, it can only touch up to 4 gaps.

4 x 4 Configuration

To get a minimal tiling, we wish to maximize the number of "4-tiles" (i.e. tiles touching 4 holes). This may be done by minimizing the size for a 4-tile at . One such configuration is shown below.

Optimal 4-tile configuration
Figure: A minimal 2×2 tile touching four gaps.

A naive solution is to just replicate this pattern repeatedly along the diagonal, like so. Since we take 5 tiles to tile each mini-grid, this gives us tiles for a grid. For e.g. for a grid shown, the naive solution gives us , but our new strategy gives .

So we already have a lower number than the original naive solution, but can we do better?

Optimal 4-tile configuration
Figure: Repeat across diagonal.

Powers of 4

Staring at the figure above, we can see that putting all our mini-grids along the diagonal is to commit the same mistake as our original naive solution.

More specifically, if we treat each mini-grid as a single square, we can see that the problem reduces once again to the original problem, except that the number of rows and columns shrink by a factor of 4. Therefore, we can squeeze more 4-tiles out by using the same strategy (except that we are now treating each mini-grid as an atomic square).

An example using is shown:

Optimal 16x16 configuration
Figure: Optimal 16 x 16 tiling.

We can recursively use this strategy for grid sizes that are powers of . The minimal number of tiles for a grid of would be given by this recursive formula (for , and ):

Which after expanding gives us the following formula for a grid of :

For example, a grid of requires tiles, a grid of requires tiles, etc.

2025 is not a power of 4

What if our grid is not a power of ? We can split it up into a series of grids that are powers of .

So we create a simple algorithm to do this. Suppose we start with a grid of size .

  • At initialization, set our current grid size
  • Find the largest such that , and partition out the sub-grid
  • Find the minimal number of tiles required for this sub-grid and add it to our current count
  • Add tiles to extend the sides to cover the full grid
  • Set and continue until
  • Use the naive solution for

Applying this algorithm to our original problem of , we have:

So using the formula (and letting to account for the additional tiles for each sub-grid) we have:

Turns out this solution is incorrect. The assumption that the minimum tiling to get a 4-tile turns out to be suboptimal.

Appendix: Code to compute number of tiles

import math

def tiles(k: int):
    return int(5 * sum(math.pow(4, i) for i in range(k)))

def largest_power(n: int):
    assert n >= 1, "Input must be a positive integer."
    k = 0
    while 4 ** k <= n:
        k += 1
    return k - 1

def main(n0: int):
    count = 0
    n = n0
    while n > 0:
        k = largest_power(n)
        count += tiles(k) + 2
        n -= 4 ** k
    assert n == 0, f"Remaining value is {n} != 0."
    return count

print(main(2025))