Contest Duration: - (local time) (120 minutes) Back to Home

## B - Unbalanced Squares Editorial by evima

The number of squares horizontally, vertically, or diagonally adjacent to a square is at most $$8$$. However, if this number is less than $$8$$, it must be odd, so we can ignore that square.

The sketch of the solution is to divide the integers into smaller ones and larger ones, and ensure that every square is adjacent to many integers on the opposite side, which makes achieving $$a\neq b$$ relatively easy.

Here are two specific ways to do so. (Where the order is not specified, fill the squares $$(i,j)$$ in lexicographically ascending order of $$(i, j)$$.)

1. First, fill all odd-indexed rows, using the integers in ascending order. Next, fill all even-indexed rows, using the remaining integers in ascending order.
2. First, fill all squares $$(i,j)$$ such that $$i+j$$ is odd, using the integers in ascending order. Next, fill all squares $$(i,j)$$ such that $$i+j$$ is even, using the remaining integers in ascending order.

posted:
last update: