A16462 | Grid Game 2
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are playing "Grid Game 2" with your friend. There is a grid with $10^9$ rows (numbered from $1$ to $10^9$ ) and $10^9$ columns (numbered from $1$ to $10^9$ ). The cell at row $r$ and column $c$ is denoted as $(r, c)$ .
Each cell can have a colour of either black or white. Initially, there are exactly $N$ black cells (numbered from $1$ to $N$ ). Black cell $i$ is located at $(R_i, C_i)$ . The rest of the cells are white.
You and your friend will alternately take turn playing on this grid, and you are playing in the first turn. In one turn, a player will choose a black cell $(r, c)$ , then toggle cells $(r - x, c - y)$ for all $0 \leq x, y < \min(r, c)$ . If a cell is toggled, then the cell becomes black if it was a white cell, and the cell becomes white if it was a black cell.
For example, the following illustration shows how the grid changes after a player chooses a black cell $(5, 4)$ in their turn.
A player who is unable to play on their turn, i.e. no remaining black cells, loses the game, and the opposing player wins the game. If you and your friend are playing optimally, determine who will win the game.
Each cell can have a colour of either black or white. Initially, there are exactly $N$ black cells (numbered from $1$ to $N$ ). Black cell $i$ is located at $(R_i, C_i)$ . The rest of the cells are white.
You and your friend will alternately take turn playing on this grid, and you are playing in the first turn. In one turn, a player will choose a black cell $(r, c)$ , then toggle cells $(r - x, c - y)$ for all $0 \leq x, y < \min(r, c)$ . If a cell is toggled, then the cell becomes black if it was a white cell, and the cell becomes white if it was a black cell.
For example, the following illustration shows how the grid changes after a player chooses a black cell $(5, 4)$ in their turn.
A player who is unable to play on their turn, i.e. no remaining black cells, loses the game, and the opposing player wins the game. If you and your friend are playing optimally, determine who will win the game.
输入格式
The first line consists of an integer $N$ ( $1 \le N \le 200\,000$ ).
Each of the next $N$ lines consists of two integers $R_i$ $C_i$ ( $1 \leq R_i, C_i \leq 10^9)$ . For $1 \leq i < j \leq N$ , $(R_i, C_i) \neq (R_j, C_j)$ .
Each of the next $N$ lines consists of two integers $R_i$ $C_i$ ( $1 \leq R_i, C_i \leq 10^9)$ . For $1 \leq i < j \leq N$ , $(R_i, C_i) \neq (R_j, C_j)$ .
输出格式
Output FIRST if you will win the game, or SECOND otherwise.
输入输出样例
输入 #1
2 2 3 2 4
输出 #1
FIRST
输入 #2
1 2 2
输出 #2
SECOND
输入 #3
13 1 1 1 4 1 5 2 1 2 4 2 5 4 1 4 2 4 4 5 1 5 2 5 4 5 5
输出 #3
SECOND
Explanation for the sample input/output #1
You can start your move by choosing $(2, 4)$ , whose effect was demonstrated in the following illustration.
The remaining black cells are $(1, 3)$ and $(1, 4)$ , each of which will only toggle itself when chosen. Whichever your friend chooses on the next move, the you can choose the remaining black cell.
Explanation for the sample input/output #2
You have only one cell to choose, and will toggle cells $(1, 1)$ , $(1, 2)$ , $(2, 1)$ , and $(2, 2)$ . Your friend and you will alternately choose the remaining black cells with your friend choosing the last black cell.
You can start your move by choosing $(2, 4)$ , whose effect was demonstrated in the following illustration.
The remaining black cells are $(1, 3)$ and $(1, 4)$ , each of which will only toggle itself when chosen. Whichever your friend chooses on the next move, the you can choose the remaining black cell.
Explanation for the sample input/output #2
You have only one cell to choose, and will toggle cells $(1, 1)$ , $(1, 2)$ , $(2, 1)$ , and $(2, 2)$ . Your friend and you will alternately choose the remaining black cells with your friend choosing the last black cell.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted