Checkers
Time limit1sMemory limit128 MB
On an N x N board, decide whether one king can capture every opponent checker in a single move of consecutive diagonal jumps, and print the unique landing sequence if so.
- Level
Hard8 of 10
- Topics
- DFS, Backtracking, Implementation, Simulation
- Solved
- No attempts yet
Problem
The cows have taken up checkers, but they are hopeless at the endgame and need your help.
You are given an checkerboard (). Only the dark squares are used for play. Each cell is one of:
-: an unused light square (never holds a piece),+: an empty dark playable square,K: one of Bessie's kings,o: an opponent's checker.
Bessie moves next. In a single move, one of her kings makes a sequence of successive diagonal jumps. To jump, the king moves along a diagonal, passing over an opponent's checker that sits on the square immediately next to it, and lands on the empty dark square immediately beyond that checker; the jumped checker is removed at once. The same king may keep jumping in any diagonal directions, as long as each jump lands on an empty dark square and passes over an opponent's checker that is still on the board. A king never jumps over an empty square, over another king, or over a checker that has already been removed, and it may not land on an occupied square.
For example, a king above a checker jumps over the o and lands on the empty square beyond it, removing that checker:
before after
K +
o +
+ K
Determine whether one king can, in a single move, jump over and remove every opponent's checker on the board, thereby ending the game. Whenever such a game-ending move exists, it is guaranteed to be unique. There is always at least one king and at least one opponent's checker on the board.
Input
- Line 1: a single integer .
- Lines 2 to : line contains characters (each one of
-,+,K, oro) describing row of the board.
Output
If one king can end the game in a single move, print the successive squares that king occupies: the first line is its starting square, and each following line is the square it lands on after each jump. Each line contains two space-separated integers, the 1-indexed row and column. If no such game-ending single move exists, print impossible.