[Solution] Black&White Ring Game CodeChef Solution
Problem
Alice and Bob are playing a game. Alice goes first.
They have a binary circular array with elements. In one move, a player can:
- Choose a circular continuous segment of the array and perform a left cyclic shift on the chosen segment.
We define the term as the number of pairs of adjacent elements with different values. Note that we also consider and as adjacent.
A player can make a move only if, for the updated array , .
The player who is unable to make a move, loses. Find the winner of the game if both players play optimally.
Note:
- For an array with elements, some circular continuous segments are , etc.
- A left cyclic shift of a segment is . Similarly, left cyclic shift of segment is .
Input Format
- The first line of input contains a single integer , the number of test cases. The description of the test cases follows.
- Each test cases consists of two lines of input.
- The first line of each test case contains a single integer , the number of elements.
- The second line of each test case contains space-separated integers .
Output Format
For each test case, if Alice will win print Alice
, otherwise print Bob
.
You may print each character in Uppercase or Lowercase. For example: BOB
, bob
, boB
, and Bob
are all identical.
Explanation:
Test case : Alice can not perform any move. Thus, Bob wins.
Test case : Alice can perform the following move:
- Choose the segment and perform left cyclic shift. Thus, becomes .
Also, as pairs of adjacent elements with different values are and . After this move, as all pairs of adjacent elements have different values. Since , this move is valid.
After performing the move, Bob has no valid move left. Thus, Alice wins.
No comments:
Post a Comment