#C8153. Optimal Game Outcome

    ID: 52104 Type: Default 1000ms 256MiB

Optimal Game Outcome

Optimal Game Outcome

You are given a grid of size R × C where each cell is either open (.) or blocked (#). Two players, Alice and Bob, play a game as follows:

  • Alice starts at the top-left cell (1,1) and Bob starts at the bottom-right cell (R,C).
  • They can move one cell at a time in the four cardinal directions (up, down, left, right) but only into open cells.
  • If either the start or the target cell is blocked, the game is immediately declared a draw.
  • If both players can reach the opponent's starting position, let \(d_A\) be the shortest path length from Alice's start to Bob's start, and \(d_B\) be the shortest path length from Bob's start to Alice's start. If \(d_A \leq d_B\), then Alice wins; otherwise, Bob wins.
  • If neither can reach the other, the result is a draw.

Assume both players play optimally. Your task is to determine the outcome of the game: "Alice", "Bob", or "Draw".

inputFormat

The input is read from standard input (stdin) and has the following format:

T
R C
row1
row2
...
rowR
... (repeated T times)

Here, T is the number of test cases. For each test case, the first line contains two integers R and C. The following R lines each contain a string of length C representing a row of the grid.

outputFormat

For each test case, print the outcome (either "Alice", "Bob", or "Draw") on a separate line to standard output (stdout).

## sample
4
3 3
.#.
.#.
..#
2 2
..
#.
4 4
....
###.
#...
....
5 5
.####
...##
.....
##...
####.
Draw

Alice Alice Bob

</p>