| NWU IUPC 2025 powered by CPS Academy |
|---|
| Finished |
Killua is a smart anime character who enjoys playing chess. However, in his world, the chess pieces behave a bit differently. He currently has a special piece called a $$$Half-Queen$$$. Its movement follows these rules:
Figure 1. Example of the Half-Queen's (at cell x=4,y=2) possible movement. You are given an $$$N×N$$$ chessboard. One cell contains Killua's half-queen, and another cell contains an enemy King. Other cells may be empty or may contain pieces (which cannot be captured or crossed).
Your task is to determine the minimum number of moves required for the Half-Queen to reach the enemy King without capturing or passing through any other piece. If it is impossible to reach the King, report that.
The first line will contain an integer $$$N$$$ ($$$2\le N \le 1000$$$). The next $$$N$$$ lines each contain a string of length $$$N$$$, representing the board. The board contains:
Print the minimum number of moves required for the Half-Queen to reach the enemy King. If it is impossible, print -1.
4 .K.. .... ..Q. ....
3
4 .K#. #... ..Q. ....
-1
| Name |
|---|


