No.3120 Lower Nim
Problem Statement
This problem is a reactive problem.
There is an integer sequence $A$ of length $N$.
You and the judge take turns alternately. You may choose whether to go first or second.
On a turn, the player performs the following series of operations. Initially, $K=10^{100}$.
- Choose an integer $x \ (1 \le x \le K)$.
- Choose $i \ (1 \le i \le N)$ satisfying $x \le A_i$.
- Update $A_i \leftarrow A_i - x,\ K \leftarrow x$.
The player who can no longer make a valid move loses, and the player who did not lose wins.
Act appropriately and win.
Constraints
- $1 \le N \le 10^4$
- $1 \le A_i \le 10^4 \ (1\le i \le N)$
- $\sum _{i=1}^{N}A_i \le 10^4$
Input and Output
First, an integer $N$ is given.
$N$
Next, the integer sequence $A$ is given on $1$ line, separated by spaces.
$A_1$ $A_2$ $\ldots$ $A_N$
Then, choose whether to go first or second, and print a string $s$ representing your choice on $1$ line.
Print First to go first, or Second to go second.
$s$
After this, the turns alternate.
Judge's Turn
The $i,x$ chosen by the judge in its operation are given on $1$ line, separated by a space.
$i$ $x$
Then, an integer $\mathrm{ret}$ representing the state of the problem is given.
$\mathrm{ret}$
- If $\mathrm{ret} = 0$, the game continues.
- If $\mathrm{ret} = -1$, it means that you lose. Terminate your program.
Your Turn
Print the $i,x$ you chose in your operation on $1$ line, separated by a space.
$i$ $x$
Then, an integer $\mathrm{ret}$ representing the state of the problem is given.
$\mathrm{ret}$
- If $\mathrm{ret} = 1$, it means that you have won. Terminate your program.
- If $\mathrm{ret} = 0$, the game continues.
- If $\mathrm{ret} = -1$, it means that you lose. Terminate your program.
Notes
- If it is determined that you will lose when the judge plays optimally, $\mathrm{ret} = -1$ may be given before the game ends.
- Flush the output each time you print.
- If your output format is incorrect or does not satisfy the constraints, the judge result may be undefined.
Sample
| Input | Output | Explanation |
|---|---|---|
2 | $N=2$ | |
1 2 | $A=(1,2)$ | |
First | You chose to go first. | |
2 1 | You operated with $i=2,x=1$. It is updated as $k\leftarrow 1$. | |
0 | The game continues. | |
1 1 | The judge operated with $i=1,x=1$. | |
0 | The game continues. | |
2 1 | You operated with $i=2,x=1$. | |
1 | Now $A=(0,0)$, and no more operations are possible. You won. |
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。