Logo
(追記) (追記ここまで)

32062번 - Grid Game 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB50292779.412%

문제

Given a grid $A$ of size $N \times M$. Each row is numbered from 1ドル$ to $N,ドル and each column is numbered from 1ドル$ to $M$. The cell at row $r$ and column $c$ is denoted as $(r, c)$.

Cell $(r, c)$ contains an integer $A_{r,c},ドル which can be either $-1$ or a non-negative integer. If $A_{r,c} = -1,ドル that means cell $(r, c)$ is impassable. Otherwise, cell $(r, c)$ is passable.

Two players will alternately take turns playing on this grid. In one turn, a player will do the following.

  1. Choose a cell with positive integer on it, and the player starts standing on that cell. Let $x$ be the integer at this starting cell.
  2. Choose a non-negative integer $y$ such that $y < x$.
  3. Suppose that the player is standing on cell $(r, c)$. Update the value of $A_{r,c}$ to $A_{r,c} \oplus x \oplus y,ドル where $\oplus$ is the bitwise operator XOR.
  4. If either cell $(r + 1, c)$ or cell $(r, c + 1)$ is passable, the player must move to either passable cell of the player’s choosing. Then, repeat from step 3.
  5. 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 $N$ $M$ (1ドル ≤ N, M ≤ 500$) representing the size of grid $A$. Each of the next $N$ lines contains $M$ integers $A_{r,c}$ (0ドル ≤ A_{r,c} ≤ 10^9$ or $A_{r,c} = -1$) representing the integer contained in cell $(r, c)$.

출력

If the first player win the game, output first in a single line. Otherwise, output second in a single line.

제한

예제 입력 1

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

예제 출력 1

first

The first player can start his turn from $(2, 2)$ and choose $y = 0$. Then, he can keep following the cells with integer 3ドル$ and update those cells to 3ドル \oplus 3 \oplus 0 = 0$. After the first turn, there is no positive integer on the grids, thus second player is unable to play.

예제 입력 2

2 2
1 1
2 -1

예제 출력 2

first

There are 5ドル$ 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 $y,ドル and the path taken by the first player. The taken paths are indicated by the red shaded cells.

예제 입력 3

1 1
-1

예제 출력 3

second

The initial grid has no positive integer cell. The second player wins the game by default.

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2022 ICPC Asia Jakarta Regional Contest H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /