#P7630. [COCI 2011/2012 #1] SKAKAC
[COCI 2011/2012 #1] SKAKAC
Description
Mirko and Slavko are playing a game.
Mirko places a knight piece on an chessboard, covers Slavko's eyes, and then moves the knight for steps, one move per second. After that, Slavko must guess the knight's final position to win.
The chessboard in this game is special, because each square is forbidden for part of the time. More precisely, each square has a positive integer label. A square labeled with the number is passable only at times seconds, and at all other times this square is forbidden. Of course, the knight may enter a square only when that square is passable.
The game starts at time . Every second, Mirko must move the knight by one step (according to the rules of chess: the knight moves in an L-shape, like the horse in Chinese chess). Please help Slavko write a program to compute all squares where the knight may be located after seconds.
Input Format
The first line contains two positive integers .
The second line contains two positive integers , representing the knight's initial coordinates.
The next lines each contain positive integers not exceeding , describing the chessboard.
Output Format
The first line contains a non-negative integer , the number of squares where the knight may be located after seconds.
The next lines each contain one coordinate, indicating a square where the knight may be located after seconds. Output the coordinates sorted by increasing row number, and if the row numbers are the same, by increasing column number.
3 2
1 1
1 3 2
2 3 2
3 1 1
2
1 1
1 3
5 6
2 3
4 5 3 2 3
1 3 4 3 1
3 4 1 3 2
4 4 2 1 3
4 6 4 9 2
5
1 4
2 1
2 5
4 5
5 2
3 3
2 2
3 6 4
2 2 5
1 3 7
0
Hint
Sample 1 Explanation
The state of the chessboard is shown in the figure below. . represents a passable square, # represents a forbidden square, and K represents a square where the knight may be located.

Constraints
For of the testdata, .
For of the testdata, , .
Notes
The score of this problem follows the original COCI settings, with a full score of .
Translated from COCI2011-2012 CONTEST #1 T6 SKAKAC.
Translated by ChatGPT 5
京公网安备 11011102002149号