#C4586. Jumping Game Winner Determination

    ID: 48140 Type: Default 1000ms 256MiB

Jumping Game Winner Determination

Jumping Game Winner Determination

In this problem, you are given a sequence of buildings represented by their heights. Two players, Alice and Bob, compete in a jumping game. The game is played as follows: starting from a given building at index (S), the current player may jump either to the right, i.e. to index (i + h_i), or to the left, i.e. to index (i - h_i), where (h_i) is the height of the building at index (i). A building cannot be visited more than once in a playthrough. Both players play optimally. If the current player can force a win by moving in such a way that the opponent is left with no valid moves, then the current player wins. Otherwise, the opponent wins. Given that Alice starts the game, determine who will win.

The solution can be obtained using a depth-first search (DFS) with backtracking. In each recursive call, valid moves are explored and if any move leads to a state where the opponent loses, the current state is winning. Otherwise, it is losing.

inputFormat

The first line contains an integer (T), the number of test cases. For each test case:

  • The first line contains two integers (N) and (S), where (N) is the number of buildings and (S) is the starting position for Alice (0-indexed).
  • The second line contains (N) space-separated integers, representing the heights of the buildings.

outputFormat

For each test case, output a single line containing either "Alice" or "Bob", denoting the winner of the game.## sample

1
5 0
2 3 1 1 4
Alice

</p>