#1044
Unrated
SKAKAC
시간 제한
1.5s
메모리 제한
64MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Ivan Katanić

Mirko and Slavko are playing the popular new game known as The Knight. Mirko places a knight chess piece on an NxN chessboard and, with Slavko blindfolded, makes exactly T moves, one per second. After that, Slavko must guess the final position of the knight in order to win. The chessboard in this game is unusual in that each square is blocked part of the time. More precisely, each square is labelled by a positive integer. A square labelled by number K is clear only during seconds 0, K, 2K, 3K etc; it is blocked at all other times. The knight can, of course, occupy a square only while the square is clear. The game begins in second 0. In each second Mirko must make a move (selecting one of 8 possible L- shaped moves, two squares in one direction and one square in the other, as per standard chess rules), provided that the destination square is not blocked during the next second. Help Slavko by writing a program to calculate all possible squares that the knight can possibly occupy after T moves.

입력

The first line of input contains two positive integers, N (3 ≤ N ≤ 30), the size of the chessboard, and T (1 ≤ T ≤ 1 000 000), the number of moves that Mirko will make. The second line of input contains two positive integers X and Y (1 ≤ X, Y ≤ N), the row and column indices of the knight’s starting square selected by Mirko. The next N lines each contain N positive integers less than 109 (one billion), the values of K for the corresponding chessboard squares.

출력

The first line of output must contain the nonnegative integer M, the number of squares that the knight can possibly occupy after T moves. The next M lines must contain indices of those squares, sorted by increasing row index, with cells in the same row sorted by increasing column index.

예제 입력 1

3 2
1 1
1 3 2
2 3 2
3 1 1

예제 출력 1

2
1 1
1 3

예제 입력 2

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

예제 출력 2

5
1 4
2 1
2 5
4 5
5 2

예제 입력 3

3 3
2 2
3 6 4
2 2 5
1 3 7

예제 출력 3

0
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.