#P12560. [UTS 2024] Randomized Palindromes

[UTS 2024] Randomized Palindromes

题目描述

You are given a binary matrix n×nn \times n consisting of zeroes and ones. Initially, you have an empty string SS. You start in the position (0;0)(0;0) (left-up corner) and move right or down. You append each element you have passed to the string SS in the respective order.

Tell whether it is possible to achieve SS being a palindrome. If yes, print the way it should pass to achieve that.

Note that each matrix is randomly generated.

输入格式

The first line contains the only integer nn (1n5000)(1 \le n \le 5\,000) --- the size of a matrix.

The following nn lines contain the nn characters ai,ja_{i,j} (0ai,j1)(0 \le a_{i,j} \le 1) --- description of the matrix.

The input matrix for the problem is picked randomly\textbf{randomly} across all possible valid matrices for the problem of size n×nn \times n.

输出格式

Print NO\tt{NO} if there is no such palindrome.

Otherwise, in the first line, print YES\tt{YES}. In each of the following 2n12n-1 lines, print two integers xix_i and yiy_i (0xi,yi<n0 \leq x_i, y_i < n) --- the coordinates of the ii-th cell.

2
01
00
YES
0 0
0 1
1 1
4
0100
1010
0100
0001
NO
4
0010
1001
1010
0010
YES
0 0
0 1
0 2
0 3
1 3
2 3
3 3

提示

  • (55 points) n10n \le 10;
  • (99 points) n100n \le 100;
  • (1919 points) n500n \le 500;
  • (2727 points) n1500n \le 1\,500;
  • (4040 points) no additional restrictions.