No.2814 Block Game
タグ : / 解いたユーザー数 29
作問者 :
Magentor
highlighter
fact493
Problem Statement
Alice and Bob are playing a game using a sequence $A$ of length $N$. Initially, $A_i=-1$ for every $i$ such that $1\leq i\leq N$.
Starting with Alice, Alice and Bob alternately perform the following series of steps.
- If there is no $i$ such that $A_i=-1$, end the game.
- If there is one, first choose an integer $x$ between $1$ and $N$, inclusive, and one $i$ such that $A_i=-1$. Here, $x$ must not be contained in $A$.
- Then, replace $A_i$ with $x$.
After the game has ended, the following operation is performed on the sequence $A$ at most $N-1$ times.
- Let $n$ be the length of $A$ at the start of the operation. Replace $A$ with $(A_1+A_2,A_2+A_3,\dots,A_{n-1}+A_{n})$.
It can be shown that in the end exactly one integer remains in $A$. Let that integer be $X$.
The outcome of this game is determined as follows, using a string $S$ that is either Odd or Even.
- When $S$ is
Odd: if $X$ is odd, Alice wins; if it is even, Bob wins. - When $S$ is
Even: if $X$ is even, Alice wins; if it is odd, Bob wins.
When both players act optimally to win, which of Alice and Bob wins?
You are given $T$ test cases; answer each of them.
Constraints
- $1\leq T\leq 2\times 10^{5}$
- $1\leq N\leq 10^{18}$
- $S$ is
OddorEven - $T,N$ are integers
Input
$T$
$\text{testcase}_1$
$\text{testcase}_2$
$\vdots$
$\text{testcase}_T$
Each test case is given in the following format.
$N$ $S$
Output
Output $T$ lines.
On the $i$-th line, for the $i$-th test case, output Alice if Alice wins, and Bob if Bob wins.
Sample
Sample 1
Input
1 3 Even
Output
Alice
In this sample input, only $1$ case is given.
For example, the game proceeds as follows.
- Initially, $(A_1,A_2,A_3)=(-1,-1,-1)$.
- Alice chooses $x=2,i=2$ and performs her steps. Now $(A_1,A_2,A_3)=(-1,2,-1)$.
- Bob chooses $x=1,i=3$ and performs his steps. Now $(A_1,A_2,A_3)=(-1,2,1)$.
- Alice chooses $x=3,i=1$ and performs her steps. Now $(A_1,A_2,A_3)=(3,2,1)$.
- There is no $i$ that Bob can declare, so the game ends.
- The operations are performed on $A$. The $1$st operation makes $A=(A_1+A_2,A_2+A_3)=(5,3)$, and the $2$nd operation makes $A=(A_1+A_2)=(8)$. Therefore, $X=8$.
- Since $S$ is
Evenand $X$ is even, Alice wins.
The players are not necessarily acting optimally here, but it can be shown that the winner is Alice even when both act optimally.
In this play, for example, it would be illegal for Alice to choose $x=1$ in her $2$nd turn, because $A_3=1$, so $1$ is already contained.
It would also be illegal for Bob to choose $i=2$ in his $1$st turn, because $A_2=2$, which is not $-1$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。