##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
2
3 K.. .KK ...
5 K.... K.... ..K.K ..... ...K.
1
3
You are given an board. Each cell is either empty . or contains a king K.
Your goal is to make every cell on the main diagonal contain a king, i.e. all cells for , using some number of moves.
In one move, you choose one king and move it to an adjacent cell that is empty. A move from to is allowed iff:
Compute the minimum number of moves needed, or determine that it is impossible.
. and KEach is a character and is either K or ..
Only is empty on the diagonal. Move the king from to in one move. So the answer is .
Diagonal cells , , and are empty.
We can fill them in moves:
At least moves are necessary because three diagonal cells are missing, and each move can place a king into at most one diagonal cell. So the answer is .