| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 36 | 14 | 11 | 35.484% |
A superknight is located on some square of a chessboard and wants to move to another square, and do so in the least possible number of moves. It is hindered by the fact that some squares are blocked and the knight is not allowed to visit them on its path.
A regular knight can move either by two rows and one column or by two columns and one row in each move (the leftmost figure). A knight can jump over blocked squares, only landing on them is forbidden (the middle figure).
A superknight differs from a regular one by its ability to perform a supermove on its path (but at most once), in which it moves either by three rows and one column or by three columns and one row (the rightmost figure).
Write a program to find the path of a superknight from a given starting square to a given destination square with the least possible number of moves.
The first line of input contains $R,ドル the number of rows, and $V,ドル the number of columns of the board (3ドル \le R \le 100,ドル 3ドル \le V \le 100$). Each of the following $R$ lines contains exactly $V$ characters, where '@' denotes the starting square of the knight, '*' the destination square, '.' a free square, and '#' a blocked square.
The first line of output should contain $K,ドル the minimal number of moves needed to reach the destination square. Each of the following $K + 1$ lines should contain two integers $r_i$ and $v_i$: the row and column numbers of the squares that the knight visits on its path, in the order they are visited. The rows of the board are numbered 1ドル \ldots R$ from top to bottom and the columns 1ドル \ldots V$ from left to right. You may assume that the knight can reach the destination square in all test cases. If there are several paths with the minimal number of moves, output any one of them.
4 5 *.... ..... ..#.. @....
4 4 1 2 2 4 3 2 4 1 1
In this example a supermove is needed to achieve the minimal number of moves. Using only regular moves, at least 5 moves would be needed. If the knight could use the supermove more than once, it could reach the destination in just 3 moves. The path $(4,1) \to (3,3) \to (1,2) \to (2,4) \to (1,1)$ would not be valid, because the knight would visit the blocked square $(3,3)$.