406341: GYM102367 C Pawn's Revenge

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Pawn's Revengetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are playing a special chess game against a professor and you've almost lost: the only piece you have left is a king. The professor just left the room to take a call, so you decided to cheat a little bit and put some extra pawns on the board so that each of opponent's pieces is under attack. As a reminder, a pawn attacks the two diagonally adjacent squares to the upper-left and upper-right of itself and a king attacks the eight adjacent squares (including the diagonally adjacent ones). You cannot put one piece on top of another piece. What is the smallest number of pawns you need to accomplish this task?

Input

The first row contains $$$N$$$, the dimension of the board, with $$$8 \leq N \leq 1000$$$. The game is played on an $$$N$$$ by $$$N$$$ chessboard. The next $$$N$$$ lines have $$$N$$$ symbols each describing the board. The symbol - means that the square is empty, * denotes a professor's piece and K denotes your king. Your pawns move upward (i.e. towards rows that appear earlier in the input).

Output

Output a line containing one number, the smallest number of pawns needed to attack all of the professor's chess pieces, or $$$-1$$$ if it is impossible to do so.

ExampleInput
8
-*-*----
--------
--------
--------
-----*K-
--------
--*-----
--------
Output
2

加入题单

算法标签: