Source: IMO-2014-P2
Category: Extremal Problems

Problem: Let $n \\geq 2$ be an integer. Consider an $n \\times n$ chessboard consisting of $n^2$ unit squares. A configuration of n rooks on this board is peaceful if every row and every column contains exactly one rook. Find the greatest positive integer $k$ such that, for each\npeaceful configuration of $n$ rooks, there is a $k \\times k$ square which does not contain a rook on any of its $k^2$ unit squares.

Answer: $k = \\lfloor \\sqrt(n-1) \\rfloor $

Reference solution:
The answer is $k = \left\lfloor \sqrt{n-1} \right\rfloor$. 

First, we prove that for any $n > k^2$, every peaceful configuration of $n$ rooks contains an empty $k \times k$ square. Let $R$ be the rook in the topmost row (row $0$). Since $n > k^2$, there are at least $k^2$ rows below $R$. Consider the $k^2$ rows immediately below $R$, and partition them into $k$ blocks of $k$ consecutive rows. Let $c$ be the column containing $R$. We can choose a block of $k$ consecutive columns that includes $c$ (this is possible since $n \ge k$). The intersection of these $k$ columns with the $k$ blocks of rows forms $k$ squares of size $k \times k$, aligned vertically directly below the row of $R$. These $k$ squares occupy $k$ columns and $k^2$ rows. Because the configuration is peaceful, these $k$ columns contain exactly $k$ rooks in total across the entire board. One of these rooks is $R$, which is located in the topmost row, outside our $k$ squares. Therefore, the $k$ squares contain at most $k-1$ rooks in total. By the Pigeonhole Principle, at least one of the $k \times k$ squares must be completely empty.

To prove this is the maximum possible $k$, we must show that for $m = k+1$, there exists a peaceful configuration of $n \le m^2$ rooks with no empty $m \times m$ square. Following the original notation, we first give an explicit construction for an $m^2 \times m^2$ board showing there may be no empty $m \times m$ square. 

Index the rows and columns from $0$ to $m^2-1$. We place a rook at $(i, j)$ if and only if $j = (i \bmod m) \cdot m + \lfloor i/m \rfloor$. 
This is a peaceful configuration: any $i \in \{0, \dots, m^2-1\}$ can be written uniquely as $i = a m + b$ with $0 \le a, b \le m-1$, placing the rook at $j = b m + a$. The mapping $(a, b) \mapsto (b, a)$ is a bijection on $\{0, \dots, m-1\}^2$, so each row and column receives exactly one rook.

To show that this works, consider for each rook drawing an $m \times m$ square of "forbidden" top-left corners whose bottom-right hand corner is the rook. A rook at $(i, j)$ forbids any $m \times m$ square whose top-left corner $(x, y)$ satisfies $x \le i \le x+m-1$ and $y \le j \le y+m-1$. We must show that these forbidden regions cover all valid top-left corners $(x, y) \in [0, m^2-m] \times [0, m^2-m]$. (Parts of the last $m-1$ columns or rows may not be covered, but they don't matter anyways since a top-left corner cannot be placed there.)

Let $(x, y)$ be an arbitrary valid top-left corner. Write $y = e m + f$ where $0 \le e \le m-1$ and $0 \le f \le m-1$.
The interval $[x, x+m-1]$ consists of $m$ consecutive integers, so it contains exactly one integer $i_1 \equiv e \pmod m$. Let $i_1 = a_1 m + e$. The corresponding rook is at $j_1 = e m + a_1$.
If $a_1 \ge f$, then $j_1 \ge e m + f = y$. Since $a_1 \le m-1$, we also have $j_1 \le e m + m - 1 \le y + m - 1$. Thus, the rook $(i_1, j_1)$ forbids $(x, y)$.

If $a_1 < f$, then $f > 0$, which implies $e < m-1$ (since $y \le m^2-m$). The interval $[x, x+m-1]$ also contains exactly one integer $i_2 \equiv e+1 \pmod m$. Let $i_2 = a_2 m + e + 1$. The corresponding rook is at $j_2 = (e+1)m + a_2$.
We have $j_2 \ge (e+1)m > e m + f = y$. We need $j_2 \le y + m - 1 = (e+1)m + f - 1$, which requires $a_2 < f$.
Since $i_1, i_2 \in [x, x+m-1]$ and $i_2 \equiv i_1 + 1 \pmod m$, we must have either $i_2 - i_1 = 1$ or $i_2 - i_1 = 1 - m$. Substituting $i_1 = a_1 m + e$ and $i_2 = a_2 m + e + 1$, we get $i_2 - i_1 = (a_2 - a_1)m + 1$. Thus, $(a_2 - a_1)m + 1 \in \{1, 1-m\}$, which implies $a_2 - a_1 \in \{0, -1\}$. In either case, $a_2 \le a_1$. Since we assumed $a_1 < f$, it follows that $a_2 < f$. Thus, the rook $(i_2, j_2)$ forbids $(x, y)$. In all cases, the $m \times m$ square contains at least one rook.

Finally, it remains to check that the construction can be adapted for all $n \le m^2$ (omitting this step is a common mistake). For this, we can delete the bottom $m^2 - n$ rows and the rightmost $m^2 - n$ columns from our $m^2 \times m^2$ board to get an $n \times n$ board. In doing so, we may have accidentally deleted some rooks. We can fill in any gaps where we deleted a rook by placing new rooks at the intersections of the empty rows and empty columns in the new $n \times n$ board to ensure it remains peaceful. Any $m \times m$ square in this $n \times n$ board is also an $m \times m$ square in the original board, meaning it originally contained at least one rook. Because the entire $m \times m$ square is preserved, the rook it contained was not deleted. Thus, the configuration remains peaceful and has no empty $m \times m$ square.

Grading guidelines:
(Partial) 1. Proved the lower bound k ≤ ⌊√(n−1)⌋ by exhibiting (for m=k+1) a peaceful configuration on an m^2×m^2 board with no empty m×m square (e.g. via the explicit permutation j=(i mod m)m+⌊i/m⌋), even if not fully justified that every m×m square meets a rook. 2. Proved the existence part in the form: if n>k^2 then every peaceful configuration has an empty k×k square, by choosing k^2 consecutive rows under the top rook, splitting into k blocks of k rows, fixing k consecutive columns through that rook, and applying pigeonhole to the k resulting k×k squares. 3. Correctly identified the claimed answer k=⌊√(n−1)⌋ and gave a coherent plan for both directions (n>k^2 implies existence; construction for n≤(k+1)^2), with at least one direction carried out rigorously. (Almost) 1. Proved both directions for the extremal value k=⌊√(n−1)⌋, but left a small gap in the construction side: did not fully prove that the constructed m^2×m^2 permutation has the property that every m×m square contains a rook (e.g. the coverage/“forbidden top-left corners” argument incomplete). 2. Proved the sharp construction for size m^2 and the existence proof for n>k^2, but did not justify the adaptation from m^2×m^2 to arbitrary n≤m^2 (e.g. deletion/refilling step or preservation of the “no empty m×m square” property). 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
For the specific case $n=233$, construct a peaceful configuration of $n$ rooks and find the minimum positive integer $l$ such that every $l \times l$ square contains at least one rook.

Construction format requirements:
- Output a single Python dictionary with keys: `'l'` and `'rooks'`.
- `'l'` is the minimum positive integer (an integer).
- `'rooks'` is a list of 233 integers, where the $r$-th integer (0-indexed) represents the column index of the rook in row $r$. Both row and column indices are integers from $0$ to $232$.
- The configuration must be peaceful, meaning every row and every column contains exactly one rook.
- Every $l \times l$ square in the $233 \times 233$ grid must contain at least one rook.
- Put ONLY the Python literal dictionary inside the construction block.

Reference construction:
{"l": 16, "rooks": [dict([(16 * i + j - 23, 16 * j + i) for i in range(16) for j in range(16) if 16 * i + j >= 23 and 16 * j + i <= 232] + list(zip(sorted([16 * i - 9 for i in range(9, 16)] + [16 * i - 8 for i in range(1, 16)]), sorted([16 * j for j in range(15)] + [16 * j + 1 for j in range(7)]))))[r] for r in range(233)]}

Verifier code:
import sys
import ast

def verify():
    payload = sys.stdin.read().strip()
    if not payload:
        print("Error: Empty input.")
        return

    try:
        # The instruction and user intent specify a Python literal parsed with ast.literal_eval.
        data = ast.literal_eval(payload)
    except Exception as e_lit:
        # Fallback to eval with restricted builtins strictly to maintain compatibility 
        # with the provided ref_construction, which uses comprehensions and specific builtins.
        try:
            allowed_builtins = {
                'dict': dict,
                'list': list,
                'zip': zip,
                'sorted': sorted,
                'range': range,
                '__builtins__': {}
            }
            data = eval(payload, allowed_builtins, {})
        except Exception:
            # If the fallback also fails, surface the original literal_eval error.
            print(f"Parse error: {e_lit}")
            return

    if type(data) is not dict:
        print("Error: The construction must be a Python dictionary.")
        return

    if set(data.keys()) != {'l', 'rooks'}:
        print("Error: The dictionary must contain exactly the keys 'l' and 'rooks'.")
        return

    l = data['l']
    if type(l) is not int:
        print("Error: 'l' must be an integer.")
        return

    if l != 16:
        print(f"Error: 'l' must be 16 (the mathematically required minimum for n=233), but got {l}.")
        return

    rooks = data['rooks']
    if type(rooks) is not list:
        print("Error: 'rooks' must be a list.")
        return

    if len(rooks) != 233:
        print(f"Error: 'rooks' must contain exactly 233 integers, but got {len(rooks)}.")
        return

    for i, c in enumerate(rooks):
        if type(c) is not int:
            print(f"Error: Element at index {i} in 'rooks' is not an integer.")
            return
        if not (0 <= c <= 232):
            print(f"Error: Element at index {i} in 'rooks' is out of bounds (must be 0-232, got {c}).")
            return

    if len(set(rooks)) != 233:
        print("Error: The configuration is not peaceful. There are duplicate column indices in 'rooks'.")
        return

    # Iterate over all possible 16x16 squares in the 233x233 grid.
    # A 16x16 square is defined by row range [R, R+15] and col range [C, C+15]
    # R and C range from 0 to 233 - 16 = 217.
    for R in range(218):
        for C in range(218):
            found = False
            for r in range(R, R + 16):
                if C <= rooks[r] <= C + 15:
                    found = True
                    break
            if not found:
                print(f"Error: The 16x16 square at rows {R}-{R+15} and columns {C}-{C+15} is completely empty.")
                return

    print("True")

if __name__ == "__main__":
    verify()