#P15623. [ICPC 2022 Jakarta R] Grid Game
[ICPC 2022 Jakarta R] Grid Game
题目描述
Given a grid of size . Each row is numbered from to , and each column is numbered from to . The cell at row and column is denoted as .
Cell contains an integer , which can be either or a non-negative integer. If , that means cell is impassable. Otherwise, cell is passable.
Two players will alternately take turns playing on this grid. In one turn, a player will do the following.
- Choose a cell with positive integer on it, and the player starts standing on that cell. Let be the integer at this starting cell.
- Choose a non-negative integer such that .
- Suppose that the player is standing on cell . Update the value of to , where is the bitwise operator XOR.
- If either cell or cell is passable, the player must move to either passable cell of the player's choosing. Then, repeat from step 3.
- If the player is no longer able to move, the player will step outside of the grid and end his turn.
A player who is unable to play on his turn (i.e. no positive integer on his turn) loses the game, and the opposing player wins the game.
If both players play optimally, determine who will win the game.
输入格式
Input begins with two integers () representing the size of grid . Each of the next lines contains integers ( or ) representing the integer contained in cell .
输出格式
Input begins with two integers () representing the size of grid . Each of the next lines contains integers ( or ) representing the integer contained in cell .
5 6
0 0 0 0 0 0
0 3 3 0 0 0
0 0 3 -1 0 0
0 0 3 3 3 3
0 0 -1 -1 -1 -1
first
2 2
1 1
2 -1
first
1 1
-1
second
提示
Explanation for the sample input/output #1
The first player can start his turn from and choose . Then, he can keep following the cells with integer and update those cells to . After the first turn, there is no positive integer on the grids, thus the second player is unable to play.
Explanation for the sample input/output #2
There are options that can be made by the first player during the first turn, as shown in the following illustration. Each option has different starting cell (abbreviated as SC), the value of , and the path taken by the first player. The taken paths are indicated by the red shaded cells.
:::align{center}
:::
The optimal moves for the first player to guarantee his win is either option or .
Explanation for the sample input/output #3
The initial grid has no positive integer cell. The second player wins the game by default.