Under construction

Still being built. Things may change

Checkers

Time limit1sMemory limit128 MB

Summary
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 N×NN \times N checkerboard (4≤N≤304 \le N \le 30). 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 NN.
  • Lines 2 to N+1N+1: line i+1i+1 contains NN characters (each one of -, +, K, or o) describing row ii 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.

Examples3

  1. Example 1

    Input
    8
    -+-+-+-+
    +-+-+-+-
    -+-K-+-+
    +-+-+-+-
    -o-o-+-+
    +-K-+-+-
    -o-+-+-+
    +-K-+-K-
    
    Expected output
    8 3
    6 1
    4 3
    6 5
    
  2. Example 2

    Input
    4
    -K-+
    +-o-
    -+-+
    +-+-
    
    Expected output
    1 2
    3 4
    
  3. Example 3

    Input
    6
    -+-+-+
    +-+-+-
    -o-+-+
    +-+-+-
    -o-+-+
    +-K-+-
    
    Expected output
    6 3
    4 1
    2 3