#P17242. [IOI 2026] 方块游戏 / Tiling Game
[IOI 2026] 方块游戏 / Tiling Game
Problem Description
Barchin and Charos are playing a game on a grid of unit square cells. The rows are numbered to from top to bottom, and the columns are numbered to from left to right. For and , we denote the cell in row and column by .
Barchin gives Charos blocks, one by one. Each block is a square consisting of four tiles. Barchin has colored every tile of the block either black or white while guaranteeing that at least one tile is white.
Charos must place each block on the grid immediately after receiving it, without knowing what blocks she will receive later. Blocks cannot be rotated. Each block must be placed entirely inside the grid, covering exactly four grid cells. Moreover, the top-left tile of each block must cover a cell whose row and column coordinates are both even. Each cell of the grid can be covered by at most one block.
Barchin wins the game if, after any block is placed, there exists a square of cells that is covered by four black tiles. Formally, if cells , , , are all covered by black tiles for some and , then Barchin wins. The indices and do not need to be even.
Charos wins if she places all blocks without Barchin ever winning. Note that placing blocks will completely cover the grid.
Your task is to implement a strategy for Charos to win the game. It can be proven that, under the given constraints, Charos can always place the blocks so as to guarantee a win, regardless of the colorings of the blocks she receives later.
Implementation Details
You should implement two procedures:
void init(int N, int M)
- : half the number of rows in the grid.
- : half the number of columns in the grid.
- The procedure is called exactly once per test case, at the beginning of the execution of your program.
std::pair<int, int> receive_block(int TL, int TR, int BL, int BR)
- , , , : the colors of the top-left, top-right, bottom-left, and bottom-right tiles of the current block, respectively, as shown in the figure below. Each value is either (white) or (black).
- This procedure is called exactly times per test case, after the initial call to init.
:::align{center}
:::
This procedure should return a pair of integers , where is the row coordinate and is the column coordinate of the cell where the top-left tile of this block should be placed. Both and must be even, and the region covered by the block must not overlap any previously placed block.
If receive_block ever returns a pair that does not satisfy these requirements, or if after placing the block a square of cells becomes completely covered by black tiles, the grader will immediately terminate your program and the verdict for the test case will be Output isn't correct.
The behaviour of the grader is not adaptive. This means that the sequence of blocks Barchin gives to Charos is fixed before init is called.
Input Format
N M
TL[0] TR[0] BL[0] BR[0]
TL[1] TR[1] BL[1] BR[1]
...
TL[NM-1] TR[NM-1] BL[NM-1] BR[NM-1]
Output Format
R[0] C[0]
R[1] C[1]
...
R[NM-1] C[NM-1]
Here, and are the pair of integers returned by the k-th call to receive_block.
Hint
Example
Consider a game with and , so the grid has rows and columns. The grader first calls:
init(1, 2)
Initially, all cells are empty. The grid looks like this:
:::align{center}
:::
There are blocks to place. Suppose Barchin gives a block with three black tiles and one white tile at the top-right corner. The grader calls:
receive_block(1, 0, 1, 1)
Charos decides to place this block at the left side of the grid by returning .
The grid now looks like this:
:::align{center}
:::
Barchin then gives another block with three black tiles and one white tile at the top-left corner:
receive_block(0, 1, 1, 1)
The only remaining cell with even row and even column that can serve as the top-left corner of a block is , so Charos returns . The grid ends up like this:
:::align{center}
:::
No square is completely covered by black tiles, so Charos has successfully placed all blocks without Barchin ever winning. Charos wins the game.
Constraints
For each block, let be the number of black tiles among its four tiles. That is .
- for every block.
Subtasks
::cute-table{tuack}
| Subtask | Score | Additional Constraints |
|---|---|---|
| for every block, and . | ||
| for every block. , is even, and each of the four possible block colorings appears exactly times. | ||
| for every block. | ||
| for every block. | ||
| No additional constraints. |