[Solution] Subarray Game CodeChef Solution
Problem
We define the goodness of any array of length as: (Here denotes the absolute value of ). In particular, goodness of any array of length is .
Alice and Bob have an array containing distinct elements and they play a game with it.
Alice starts the game after which both the players make moves alternatively. In one move:
- A player can delete any subarray from such that the goodness of does not change.
Formally, the player chooses indices and such that and removes the subarray from such that the goodness of does not change.
For e.g. , a player can select , then the resulting array will be . Initially, the goodness was . After the move, the goodness is . Here we can observe that the goodness does not change.
The player who is not able to make a move loses. If both the players play optimally, determine who out of Alice and Bob
will win the game.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the array .
- The second line of each test case contains space-separated integers denoting the array .
Output Format
For each test case, output the winner of the game if both players play optimally.
You may print each character of Alice
and Bob
in uppercase or lowercase (for example, aLiCe
, ALIce
, alice
will be considered identical).
Explanation:
Test case 1: Alice can not make any moves such that the goodness of the array does not change. Therefore Bob wins.
Test case 2: Alice can choose and remove the subarray . The resulting array is .
- Goodness of the array before the operation .
- Goodness of the array after the operation .
Thus, the array has the same goodness as before. Now Bob can not make any move. Therefore Alice wins.
No comments:
Post a Comment