#K56407. Crystal Collection Game

    ID: 30191 Type: Default 1000ms 256MiB

Crystal Collection Game

Crystal Collection Game

Alice and Bob are playing a game on a grid representing a forest path. Some cells contain crystals denoted by C, some are empty (denoted by .), and some may be obstacles (denoted by #). From the starting cell at the top‐left corner (cell (0, 0)), Alice collects all crystals reachable via moves in the four cardinal directions (up, down, left, right), but cannot pass through obstacles. Bob collects all remaining crystals, i.e. all crystals that are not at the starting position (regardless of connectivity).

Determine the winner based on the following rule:

  • If the number of crystals collected by Alice is greater than Bob’s, the winner is ALICE.
  • If Bob collects more than Alice, the winner is BOB.
  • If both collect the same number of crystals, the game ends in a DRAW.

Mathematically, if we let \(A\) be the number of crystals in the connected component (reachable from (0, 0)) and \(T\) be the total number of crystals in the grid, and assuming the starting cell contributes to Alice if it contains a crystal, then Bob's crystals are given by \(B = T - [\text{1 if the starting cell has a crystal, otherwise }0]\). The winner is determined by comparing \(A\) and \(B\).

inputFormat

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

M N
row1
row2
...
rowM

Here, M and N are integers representing the number of rows and columns in the grid respectively. Each of the following M lines contains a string of N characters, where each character is either C for a crystal, . for an empty cell, or # for an obstacle.

outputFormat

Output a single line to standard output (stdout) containing one of the following strings: ALICE, BOB, or DRAW, according to the rules described above.

## sample
3 3
C.C
.C.
C.C
ALICE