No.2666 Decreasing Modulo Nim
タグ : / 解いたユーザー数 72
作問者 :
cureskol
Problem Statement
You are given a sequence of positive integers $A=(A_1,A_2,\ldots,A_n)$ of length $n$ and a positive integer $m$. In addition, a non-negative integer $x$ is initialized as $x = m - 1$.
Alice and Bob play a game using this sequence. Starting with Alice, they alternately perform the following operation.
- Choose a pair of integers $(i,k)$ satisfying $1\leq k\leq A_i$ and $(k\bmod m) \leq x$, and update $A_i\gets A_i-k,\ x\gets (k\bmod m)$. Here, $a\bmod b$ denotes the remainder when $a$ is divided by $b$.
The player who becomes unable to perform the operation loses, and the other player wins.
Determine which player wins when both players play optimally to win.
Input
The input is given from Standard Input in the following format.
$n$ $m$ $A_1$ $A_2$ $\cdots$ $A_n$
- All input values are integers.
- $1\leq n\leq 2\times 10 ^ 5$
- $1\leq m\leq 10 ^ 9$
- $1\leq A_i\leq 10 ^ 9$
Output
If Alice wins, print Alice; if Bob wins, print Bob, on $1$ line, followed by a newline.
Sample
Sample 1
Input
3 2 1 2 3
Output
Bob
This input represents $n=3,\ m=2,\ A=(1,2,3)$.
An example of how the game may proceed is shown below. Note that this example does not necessarily represent optimal play by both players.
- For $A=(1,2,3),\ x=m-1=1$, Alice chooses $(i,k)=(3,1)$ and updates $A=(1,2,2),\ x=(1 \bmod 2)=1$.
- For $A=(1,2,2),\ x=1$, Bob chooses $(i,k)=(1,1)$ and updates $A=(0,2,2),\ x=(1 \bmod 2)=1$.
- For $A=(0,2,2),\ x=1$, Alice chooses $(i,k)=(3,2)$ and updates $A=(0,2,0),\ x=(2 \bmod 2)=0$.
- For $A=(0,2,0),\ x=0$, Bob chooses $(i,k)=(2,2)$ and updates $A=(0,0,0),\ x=(2 \bmod 2)=0$.
- For $A=(0,0,0),\ x=0$, Alice cannot perform the operation, so the winner in this case is Bob.
It can be proved that no matter what operations Alice performs, Bob can operate so that Bob wins. Therefore, in this case, Bob wins when both players play optimally.
Sample 2
Input
4 10 1 2 3 4
Output
Alice
Sample 3
Input
10 5 7 4 10 15 9 4 1 13 5 6
Output
Alice
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。