#P11072. Alice and Bob's Rearrangement Game

    ID: 13128 Type: Default 1000ms 256MiB

Alice and Bob's Rearrangement Game

Alice and Bob's Rearrangement Game

Alice and Bob are playing a game with an integer sequence \(a\) where every element is in the range \(0\) to \(n\). The game is played as follows:

  1. Initially, a sequence \(a = [a_1, a_2, \dots, a_m]\) is given. The first element \(a_1\) (which lies between \(0\) and \(n\)) determines the size of a subarray: the next \(a_1\) elements \(a_2, a_3, \dots, a_{a_1+1}\) will be used in the first move.
  2. The players take turns making a move, with Alice moving first.
  3. On a move, if the current first element \(a_1 = 0\) then the player whose turn it is loses immediately (since no move is possible).
  4. Otherwise, the player is allowed to arbitrarily rearrange the subarray from index 2 up to index \(a_1+1\) (that is, the segment \(a_2, a_3, \dots, a_{a_1+1}\)). After reordering, the first element of the sequence is set to the first element of the rearranged subarray. In other words, the player chooses a new value for \(a_1\) from among the elements of this subarray.
  5. However, if during the course of the game a player makes a move that results in a first element value which he or she has already produced in one of his/her previous moves, then that player loses immediately.

Under the assumption that both players play optimally, determine who has a winning strategy.


Observation and Hint: Notice that since the moving player has full control over the ordering of the designated subarray, he or she can choose any element from this subarray as the next \(a_1\) provided that it has not been chosen by him/her before. In particular, if the subarray contains a zero and this value has not been chosen by the current player, then he or she may choose it in order to force the opponent to face a state where \(a_1=0\) (and hence lose immediately when it becomes their turn). It turns out that an optimal strategy exists which is very simple to implement: if the initial first element is nonzero and the available subarray (namely \(a_2, a_3, \dots, a_{a_1+1}\)) contains at least one zero then Alice can force a win; otherwise Bob will win. (Note: The initial configuration is considered to be given; the history of produced values is empty at the start.)

Your task is to decide the winner based on the given sequence \(a\).

inputFormat

The input consists of two lines:

  1. The first line contains a positive integer \(m\) which is the length of the sequence \(a\).
  2. The second line contains \(m\) space-separated nonnegative integers \(a_1,a_2,\dots,a_m\), where \(a_1\) is in \([0,n]\) and the other elements are also in \([0,n]\). It is guaranteed that \(a_1\) does not exceed \(m-1\) (so that the subarray \(a_2\) to \(a_{a_1+1}\) is well defined).

outputFormat

Output a single line containing either Alice or Bob indicating the winner when both play optimally.

Explanation:

  • If \(a_1 = 0\), then Alice loses immediately, so output should be Bob.
  • If \(a_1 \neq 0\) and the subarray \(a_2, a_3, \dots, a_{a_1+1}\) contains a zero, then Alice can choose 0 (which she has not chosen before) on her first move to force Bob into a losing position. Thus, output Alice.
  • Otherwise, output Bob.

sample

1
0
Bob