#P1971. Rabbit's Chess Mistakes
Rabbit's Chess Mistakes
Rabbit's Chess Mistakes
Recently, Rabbit (兔兔) and Egg (蛋蛋) have been playing a new board game on an n×m board. Initially, exactly one cell is empty, and every other cell contains a piece that is either black or white. The game proceeds as follows:
- The game always starts with Rabbit.
- On Rabbit's turn, she must choose a white piece adjacent (sharing a common edge) to the empty cell and slide it into the empty cell. This move is denoted as \(M(x,y)\), indicating that the piece from row \(x\) and column \(y\) is moved into the empty cell.
- On Egg’s turn, he must choose a black piece adjacent to the empty cell and slide it into the empty cell.
- If a player cannot make a move according to these rules, that player loses.
Rabbit defines one of her moves as a mistake if and only if:
[ \text{(Before the move, Rabbit has a winning strategy)} \quad \wedge \quad \text{(After the move, Egg has a winning strategy)} ]
You are given a complete transcript of a game in which Rabbit eventually lost. Your task is to identify, among Rabbit’s moves, all the moves where she committed a mistake.
Note:
- Two cells are adjacent if and only if they share a common edge.
- The transcript lists the moves in order. Moves are denoted by \(M(x,y)\), meaning that the piece originally in row \(x\) and column \(y\) is slid into the empty cell.
inputFormat
The first line contains two integers \(n\) and \(m\) (the dimensions of the board).
The next \(n\) lines each contain a string of length \(m\), representing the initial configuration of the board. Each character is one of:
'W'
representing a white piece,'B'
representing a black piece,'.'
representing the empty cell (appearing exactly once).
The next line contains an integer \(k\), the total number of moves in the transcript.
Each of the next \(k\) lines contains two integers \(x\) and \(y\) (1-indexed), representing the move \(M(x,y)\) i.e. moving the piece from row \(x\) and column \(y\) into the empty cell.
outputFormat
Output a single line containing the 1-indexed move numbers of all of Rabbit’s moves that were mistakes, in increasing order, separated by a single space. If Rabbit made no mistakes, output a single 0.
sample
2 2
W.
BW
1
1 1
0
</p>