Grid Game
시간 제한2초메모리 제한1024 MB
두 플레이어가 번갈아 양수 칸을 골라 값을 더 작은 XOR 결과로 바꾸고 오른쪽이나 아래로 이동하며, 최적 플레이에서 승자를 가린다.
문제
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 .
출력
If the first player win the game, output first in a single line. Otherwise, output second in a single line.