Source: USEMO-2022-P1
Category: Extremal Problems

Problem: A \"stick\" is a $1\\times k$ or $k\\times 1$ rectangle, where $k$ is any positive integer. Find the smallest positive integer $m$ such that a $2022\\times2022$ board can be partitioned into $m$ disjoint sticks, and any two sticks share at most one unit-length common edge.

Answer: 2042224

Reference solution:
Let the $2022 \times 2022$ board be partitioned into $m$ disjoint sticks. Each stick is a rectangle of dimensions $1 \times k$ or $k \times 1$ for some integer $k \ge 1$, and thus has exactly $4$ vertices. Therefore, the total number of vertices of the $m$ sticks is $4m$.

We count the number of stick vertices located at the grid points of the board.
- **Interior points:** There are $2021^2$ grid points strictly inside the board. Consider any such interior point $P$. It is shared by $4$ unit squares. If $P$ were a vertex of $0$ sticks, the $4$ squares meeting at $P$ would be covered by sticks that pass straight through $P$. Because sticks have width $1$, this requires exactly two sticks to cover the $4$ squares (either two horizontal sticks or two vertical sticks). These two sticks would then share a boundary segment of length $2$ centered at $P$, meaning they share two unit-length common edges. This contradicts the condition that any two sticks share at most one unit-length common edge. If $P$ were a vertex of exactly $1$ stick, that stick would cover exactly $1$ of the $4$ squares meeting at $P$. The remaining $3$ squares cannot be covered by a single stick passing straight through $P$ (which would cover exactly $2$ squares), meaning at least one more stick must have a corner at $P$, making it a vertex of at least $2$ sticks. Thus, every interior point must be a vertex of at least $2$ sticks.
- **Corner points of the board:** There are $4$ corner points of the board. Each is incident to exactly $1$ square of the board, so each must be a vertex of exactly $1$ stick.
- **Boundary points (non-corners):** Consider the $4$ corner squares of the board. Each is covered by some stick. Since a stick has width $1$ and cannot extend outside the board, the stick covering a corner square must end at one or both of the boundary points adjacent to the corner. Thus, among the two boundary points adjacent to any corner of the board, at least one is a vertex of this stick. Because a non-corner boundary point is incident to exactly $2$ squares of the board, any stick vertex at this point must be paired with another stick vertex (a stick cannot pass straight through the boundary and exit the board). Thus, this point is a vertex of exactly $2$ sticks. Since the board is $2022 \times 2022$, these $4$ boundary points (at least one for each corner) are distinct. Hence, there are at least $4$ non-corner boundary points that are vertices of exactly $2$ sticks.

Summing the number of stick vertices over all grid points, we obtain:
$$ 4m \ge 2 \times 2021^2 + 1 \times 4 + 2 \times 4 $$
$$ 4m \ge 2(4084441) + 4 + 8 $$
$$ 4m \ge 8168882 + 12 = 8168894 $$

Dividing by $4$ yields:
$$ m \ge \frac{8168894}{4} = 2042223.5 $$

Since $m$ must be an integer, we conclude that the smallest positive integer $m$ is $2042224$.

Grading guidelines:
(Partial) 1. Introduced counting of stick corners/vertices and the identity that each stick contributes exactly 4 vertices, so total stick-vertex count is 4m. 2. Proved the key local restriction at an interior grid point P: P cannot be a vertex of 0 sticks (else two sticks must pass straight and share a length-2 boundary, violating the “at most one unit edge” condition). 3. Proved that every interior grid point must be a vertex of at least 2 sticks (ruled out “exactly 1 stick has a corner at P” by showing the remaining 3 unit squares around P cannot be covered without another corner at P). (Almost) 1. Derived the lower bound 4m ≥ 2·2021^2 + 4 + (boundary contribution), and correctly concluded m ≥ 2042224, but the argument for the needed boundary contribution (at least four non-corner boundary points that are vertices of exactly 2 sticks) is incomplete or not fully justified. 2. Carried out the full vertex-counting approach and reached m ≥ 2042223.5, but made a localized counting slip (e.g., miscounted interior points as 2022^2 or mishandled corner/boundary points), while the overall method and use of the “share at most one edge” condition are correct. 3. Solution is almost complete, but made minor mistakes which are not negligible.

Construction task:
Solve the original problem, but for a concrete 10 \times 10 board: output exactly one explicit partition achieving the minimum possible number of sticks under the same rules. Your final answer must consist of exactly one construction enclosed in <construct>...</construct>, where the payload is a single Python expression that evals to a 10\times 10 matrix (list of 10 lists of length 10) of integers. Equal integers denote cells belonging to the same stick; different integers denote different sticks. Each label's cells must form a single 1\times k or k\times 1 rectangle (k\geq 1) and the sticks must partition the grid. Any two distinct sticks may share at most one unit-length common edge in total. The set of labels used must be exactly {1,2,\cdots ,M} for some M, each used at least once, and M must be as small as possible for the 10×10 case.

Reference construction:
[[6 if r == 0 and c < 8 else 7 if r == 0 else 44 if r == 9 else 1 if c == 0 else 2 if c == 2 else 3 if c == 4 else 4 if c == 6 else 5 if c == 9 else 8 + 9 * ((r - 1) // 2) + (0 if r % 2 == 1 else 4) + {1: 0, 3: 1, 5: 2, 7: 3, 8: (3 if r % 2 == 1 else 4)}[c] for c in range(10)] for r in range(10)]

Verifier code:
import sys
import ast
from collections import defaultdict

def fail(msg):
    print(msg)
    sys.exit(0)

src = sys.stdin.read()

# 1) Evaluate payload in restricted environment
safe_globals = {
    "__builtins__": {},
    "range": range,
    "list": list,
    "dict": dict,
    "set": set,
    "tuple": tuple,
    "len": len,
    "min": min,
    "max": max,
    "sum": sum,
    "abs": abs,
    "sorted": sorted,
    "enumerate": enumerate,
    "zip": zip,
}
try:
    tree = ast.parse(src, mode="eval")
except Exception as e:
    fail(f"Parse error: {e}")

try:
    code = compile(tree, "<stdin>", "eval")
    obj = eval(code, safe_globals, {})
except Exception as e:
    fail(f"Eval error: {e}")

# 2) Confirm 10x10 matrix of strict ints
if not isinstance(obj, list):
    fail("Dimensions/type error: top-level must be a list (10 rows).")
if len(obj) != 10:
    fail(f"Dimensions error: expected 10 rows, got {len(obj)}.")
grid = obj
for r, row in enumerate(grid):
    if not isinstance(row, list):
        fail(f"Dimensions/type error: row {r} must be a list.")
    if len(row) != 10:
        fail(f"Dimensions error: row {r} expected length 10, got {len(row)}.")
    for c, v in enumerate(row):
        if type(v) is not int:
            fail(f"Cell type error: grid[{r}][{c}] must be a strict int, got {type(v).__name__}.")

# 3) Labels must be exactly {1..44}
labels = set()
for row in grid:
    labels.update(row)

if not labels:
    fail("Label error: no labels found.")
mn, mx = min(labels), max(labels)
if mn != 1:
    fail(f"Label set error: minimum label must be 1, got {mn}.")
if mx != 44:
    fail(f"Label set error: maximum label must be 44, got {mx}.")
expected = set(range(1, 45))
missing = sorted(expected - labels)
extra = sorted(labels - expected)
if missing or extra:
    if missing and extra:
        fail(f"Label set error: missing {missing}, extra {extra}.")
    if missing:
        fail(f"Label set error: missing labels {missing}.")
    fail(f"Label set error: extra labels {extra}.")

# 4) Each label forms one stick: fills bounding box, and box is 1xk or kx1
coords = {t: [] for t in range(1, 45)}
for r in range(10):
    for c in range(10):
        coords[grid[r][c]].append((r, c))

for t in range(1, 45):
    cells = coords[t]
    if not cells:
        fail(f"Stick error: label {t} is unused.")
    rs = [p[0] for p in cells]
    cs = [p[1] for p in cells]
    rmin, rmax = min(rs), max(rs)
    cmin, cmax = min(cs), max(cs)
    h = rmax - rmin + 1
    w = cmax - cmin + 1

    if not (h == 1 or w == 1):
        fail(f"Stick shape error: label {t} bounding box is {h}x{w}, not a 1xk or kx1 stick.")

    cellset = set(cells)
    expected_box = {(rr, cc) for rr in range(rmin, rmax + 1) for cc in range(cmin, cmax + 1)}
    if cellset != expected_box:
        missing_in_box = expected_box - cellset
        extra_outside = cellset - expected_box
        if missing_in_box:
            ex = next(iter(missing_in_box))
            fail(f"Stick fill error: label {t} does not fill its bounding box; missing cell {ex}.")
        ex = next(iter(extra_outside))
        fail(f"Stick fill error: label {t} has cell outside its bounding box? example {ex}.")

# 5) Any unordered label pair shares at most one unit-length common edge
shared = defaultdict(int)

for r in range(10):
    for c in range(10):
        a = grid[r][c]
        if c + 1 < 10:
            b = grid[r][c + 1]
            if a != b:
                x, y = (a, b) if a < b else (b, a)
                shared[(x, y)] += 1
        if r + 1 < 10:
            b = grid[r + 1][c]
            if a != b:
                x, y = (a, b) if a < b else (b, a)
                shared[(x, y)] += 1

for (x, y), cnt in shared.items():
    if cnt > 1:
        fail(f"Shared-boundary error: labels {x} and {y} share {cnt} unit edges (>1).")

print("True")