This page is still under construction.

Parts of this page are still being built. What you see may change.

Board Game

Time limit1sMemory limit128 MB

Summary
Two pieces move on a small board with holes; positions cannot repeat, so decide which player wins under optimal play.
Level

Hard8 of 10

Topics
Game theory, Graph, BFS, Simulation
Solved
No attempts yet

Problem

Alice and Bob play the following game. There is an m×nm \times n chessboard with some fields removed. Two pieces stand on two distinct, non-removed fields. Alice moves first, and then she and Bob alternate turns. On a turn a player moves one of the two pieces by one field horizontally or vertically. Either player may move either piece, regardless of which piece was moved on the previous turn. A piece may not be moved onto a removed field. If a player moves a piece onto the field occupied by the other piece, that piece is captured and the player wins.

After a while the game became boring: nobody could win and the pieces just chased each other. So they added a new rule: no player may move a piece so that a position that already occurred earlier in the game is repeated. A position is determined only by the set of fields occupied by the pieces (the two pieces are indistinguishable) and does not depend on whose turn it is. In addition, a player who cannot make a legal move loses. The game is now always finite and exactly one player wins. Determine who wins under optimal play.

Input

The input consists of several instances, separated by single blank lines.

The first line of each instance contains two integers mm and nn (1≤m,n≤81 \le m, n \le 8). Each of the following mm lines contains nn characters describing the initial state of the board. Each character is one of:

  • . for an empty field
  • # for a removed field
  • P for a field where one of the pieces starts

Each instance contains exactly two P characters.

Output

For each instance, output a single line containing Alice wins. if Alice has a winning strategy, or Bob wins. otherwise.

Examples3

  1. Example 1

    Input
    4 4
    P.##
    ..##
    ##..
    ##.P
    
    1 5
    P...P
    
    Expected output
    Alice wins.
    Bob wins.
    
  2. Example 2

    Input
    1 2
    PP
    
    Expected output
    Alice wins.
    
  3. Example 3

    Input
    2 2
    P.
    .P
    
    Expected output
    Bob wins.