Source: USEMO-2021-P6
Category: Extremal Problems

Problem: A \"doughnut\" is a ring formed by removing an $a \\times b$ rectangle from the center of an $(a+2) \\times (b+2)$ rectangle, consisting of $2a + 2b + 4$ unit squares, where $a$ and $b$ are arbitrary positive integers. Consider an infinite grid. For each even $n \\geq 8$, an \"$n$-order bakery\" is a finite set $S$ of squares such that for any doughnut $B$ composed of $n$ squares, there exists a doughnut congruent to $B$ (by translation and rotation) whose squares all belong to $S$. Let $f(n)$ denote the minimum possible number of squares in an $n$-order bakery. Find the real number $\\alpha$ such that for all sufficiently large even $n$, we have $\\frac{1}{100} < \\frac{f(n)}{n^\\alpha} < 100$.

Answer: \\frac{3}{2}

Reference solution:
We say that $g(n)$ is "at least arbitrarily close" to $h(n)$ if 
\[
\lim_{n\to\infty}\frac{g(n)}{h(n)}\ge 1.
\] 
A similar definition gives "at most arbitrarily close." Since this problem concerns only sufficiently large integers, we may work in the above sense. 

We first prove that $f(n)$ is at least arbitrarily close to 
\[
\frac{1}{8}n^{\frac{3}{2}}.
\] 

Call a doughnut "horizontal" if its longer side lies in a row of the grid. Assume that at least half of the doughnuts in $S$ are horizontal. Because there are $\lfloor \frac{n}{4}-1 \rfloor$ distinct doughnuts, there are at least $\frac{n}{8}-1$ horizontal doughnuts. 

Let the longer sides of these horizontal doughnuts lie in $k$ rows of $S$. Since their shorter sides are all different, we must choose pairs of rows to form the horizontal boundaries. Thus, we have 
\[
\binom{k}{2}\ge \frac{n}{8}-1,
\] 
which implies that $k$ is at least arbitrarily close to 
\[
\frac{\sqrt{n}}{2}.
\] 

Each longer side contains at least $\frac{n}{4}+1$ squares of $S$, so 
\[
f(n)\text{ is at least arbitrarily close to }\frac{\sqrt{n}}{2}\cdot\frac{n}{4}
= \frac{1}{8}n^{\frac{3}{2}}.
\] 

We now prove that $f(n)$ is at most arbitrarily close to $\sqrt{2}\,n^{\frac{3}{2}}$.  
Let $l=\left\lceil\sqrt{\frac{n}{2}}\right\rceil$, and define $S$ to consist of grid squares $(x,y)$ with $1\le x,y\le l^{2}$ such that at least one of $x,y$ belongs to the set  
\[
A=\{1,2,\dots,l\}\cup\{2l,3l,\dots,l^{2}\}.
\]
Note that $\{1,2,\dots,l^{2}-1\}\subseteq\{a_{1}-a_{2}\mid a_{1},a_{2}\in A\}$, i.e., every integer from $1$ to $\frac{n}{2}-1$ can be expressed as the difference of two elements of $A$.  
Moreover, each doughnut consisting of $n$ squares has its longer side containing at most $\frac{n}{2}-1$ squares, so any such doughnut can be placed entirely inside $S$.  

At this point, the number of coordinates in $\{1, 2, \dots, l^2\}$ not in $A$ is $l^2 - (2l-1) = (l-1)^2$. The number of squares $(x,y)$ where neither coordinate is in $A$ is therefore $((l-1)^2)^2 = (l-1)^4$. Thus, $S$ contains exactly $l^{4}-(l-1)^{4}$ squares. Because $l^{4}-(l-1)^{4} = 4l^3 - 6l^2 + 4l - 1$, $f(n)$ is at most arbitrarily close to $4l^{3}$, i.e., $\sqrt{2}\,n^{\frac{3}{2}}$. 

Since $f(n)$ is bounded between $\sim \frac{1}{8}n^{3/2}$ and $\sim \sqrt{2}n^{3/2}$ for large $n$, we conclude that the real number $\alpha$ satisfying $\frac{1}{100} < \frac{f(n)}{n^\alpha} < 100$ for all sufficiently large $n$ is $\alpha = \frac{3}{2}$.

Grading guidelines:
(Partial) 1. Established a nontrivial lower bound of the form f(n) \ge c\,n^{3/2} (e.g. by counting many distinct doughnut shapes and relating them to pairs of rows/columns, obtaining a \binom{k}{2} bound and hence k \gg \sqrt n). 2. Established a nontrivial upper bound of the form f(n) \le C\,n^{3/2} by explicitly constructing a bakery S with |S| = O(n^{3/2}) and explaining how any n-square doughnut can be translated/rotated into S. 3. Correctly reduced the problem to determining the growth exponent by proving both f(n)=\Omega(n^{3/2}) and f(n)=O(n^{3/2}) (even with weak/unspecified constants), hence identifying \alpha=3/2 but with major gaps in at least one direction. (Almost) 1. Proved the lower bound via the “horizontal doughnuts” counting argument (many distinct horizontal shapes; their long sides lie in k rows; need \binom{k}{2} at least the number of shapes; conclude k\ge(1/2+o(1))\sqrt n; then |S|\ge k\cdot(n/4+O(1)) ), but made a small slip in the exact count of distinct doughnuts or the ‘at least half are horizontal’ step. 2. Gave essentially the full explicit construction with l=\lceil\sqrt{n/2}\rceil and a set A so that every length \le n/2-1 is a difference of two elements of A, and computed |S|=l^4-(l-1)^4=4l^3+O(l^2), but left a minor gap in justifying that every doughnut’s longer side length is \le n/2-1 or in the “difference set covers all needed side-lengths” claim. 3. Completed both bounds and concluded \alpha=3/2, but omitted a boundary case (e.g. rotations/which side is longer, or small exceptional n) or had a localized non-negligible mistake in the constant-factor estimates while the exponent argument is correct.

Construction task:
Provide an explicit construction of a bakery for $n=448$.

Construction format requirements:
- Output a single Python list of lists of integers representing a 2D matrix of 0s and 1s.
- The matrix can be of any size, but it must contain at most 12300 ones.
- For every possible valid doughnut composed of exactly $n=448$ unit squares, the matrix must contain at least one congruent copy (up to translation and rotation) made entirely of 1s.
- A doughnut is formed by removing an $a \times b$ rectangle from the center of an $(a+2) \times (b+2)$ rectangle, consisting of $2a + 2b + 4$ unit squares ($a, b \ge 1$).

Output formatting requirements:
- Include exactly one construction block and put ONLY the Python list comprehension or literal between the tags:
<construct>
...
</construct>
- Do not use markdown formatting (no ```python ... ```).
- The payload must be a single evaluable Python expression.

Reference construction:
[[0 if (r >= 15 and r % 15 != 14) and (c >= 15 and c % 15 != 14) else 1 for c in range(225)] for r in range(225)]

Verifier code:
import sys

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

    try:
        # Use eval to support list comprehensions as seen in the reference construction.
        # This is necessary because ast.literal_eval does not support comprehensions.
        matrix = eval(payload)
    except Exception as e:
        print(f"Failed to parse input: {e}")
        return

    if not isinstance(matrix, list):
        print("Input must be a list of lists.")
        return

    if len(matrix) == 0:
        print("Matrix cannot be empty.")
        return

    num_rows = len(matrix)
    if not all(isinstance(row, list) for row in matrix):
        print("Input must be a list of lists.")
        return

    num_cols = len(matrix[0])
    if num_cols == 0:
        print("Matrix rows cannot be empty.")
        return

    for row in matrix:
        if len(row) != num_cols:
            print("Matrix must be rectangular.")
            return
        for cell in row:
            if cell not in (0, 1):
                print("Matrix must contain only 0s and 1s.")
                return

    total_ones = sum(sum(row) for row in matrix)
    if total_ones > 12300:
        print(f"Matrix contains {total_ones} ones, which exceeds the maximum allowed of 12300.")
        return

    # Precompute contiguous horizontal 1s to the right
    horiz = [[0] * num_cols for _ in range(num_rows)]
    for r in range(num_rows):
        cnt = 0
        for c in range(num_cols - 1, -1, -1):
            if matrix[r][c] == 1:
                cnt += 1
            else:
                cnt = 0
            horiz[r][c] = cnt

    # Precompute contiguous vertical 1s downwards
    vert = [[0] * num_cols for _ in range(num_rows)]
    for r in range(num_rows - 1, -1, -1):
        for c in range(num_cols):
            if matrix[r][c] == 1:
                vert[r][c] = 1 + (vert[r+1][c] if r + 1 < num_rows else 0)
            else:
                vert[r][c] = 0

    # Collect all coordinates of 1s to optimize the search
    ones = [(r, c) for r in range(num_rows) for c in range(num_cols) if matrix[r][c] == 1]

    def check_doughnut_fast(a, b):
        """
        Checks if a doughnut of size (a+2) x (b+2) exists in the matrix.
        The top-left corner of the doughnut must be at some (r, c).
        """
        for r, c in ones:
            if r + b + 1 < num_rows and c + a + 1 < num_cols:
                if horiz[r][c] >= a + 2 and \
                   horiz[r+b+1][c] >= a + 2 and \
                   vert[r][c] >= b + 2 and \
                   vert[r][c+a+1] >= b + 2:
                    return True
        return False

    # Iterate through all possible integer pairs (a, b) such that a >= 1, b >= 1, and a + b = 222
    for a in range(1, 222):
        b = 222 - a
        
        # Verify that the matrix contains the corresponding doughnut.
        # We check both (a+2)x(b+2) and (b+2)x(a+2) to account for valid rotations.
        if not (check_doughnut_fast(a, b) or check_doughnut_fast(b, a)):
            print(f"Missing doughnut for a={a}, b={b}.")
            return

    print("True")

if __name__ == "__main__":
    verify()