#P7630. Knight's Forbidden Moves
Knight's Forbidden Moves
Knight's Forbidden Moves
Mirko and Slavko are playing a game. Mirko places a knight on an \(N \times N\) chessboard and covers Slavko's eyes. Then, starting at time \(0\), Mirko moves the knight for exactly \(T\) steps (one move per second, following the standard chess knight moves). After \(T\) seconds, Slavko must guess all the possible squares on which the knight could have ended up.
The board is special: each cell is marked with a positive integer \(K\). A cell with the value \(K\) is accessible only at times \(t\) where \(t\) is a multiple of \(K\) (i.e. \(t=0, K, 2K, 3K, \ldots\)). The knight can move into a cell at time \(t\) only if that cell is accessible at that exact time.
Your task is to help Slavko by determining all possible cells where the knight might be after \(T\) moves.
inputFormat
The first line contains two integers \(N\) and \(T\) representing the size of the board and the number of moves respectively.
The second line contains two integers \(r\) and \(c\) (0-indexed) representing the starting position of the knight.
Then follow \(N\) lines, each containing \(N\) positive integers. The \(j\)-th number in the \(i\)-th line represents the integer \(K_{ij}\) assigned to the cell at row \(i\) and column \(j\). A cell is accessible at time \(t\) if and only if \(t \equiv 0 \pmod{K_{ij}}\).
outputFormat
Output all possible positions of the knight after exactly \(T\) moves. Each position should be printed on a separate line as two integers (row and column). The positions should be sorted first by row and then by column. If no cell is reachable, output nothing.
sample
3 1
0 0
1 1 1
1 1 1
1 1 1
1 2
2 1
</p>