Codeforces Global Round 22
G
Anti-Increasing Addicts
Codeforces
2900
原题
← FH →
翻译中…

You are given an $n \times n$ grid.

翻译中…

We write $(i, j)$ to denote the cell in the $i$-th row and $j$-th column. For each cell, you are told whether yon can delete it or not.

翻译中…

Given an integer $k$, you are asked to delete exactly $(n-k+1)^2$ cells from the grid such that the following condition holds.

翻译中…
  • You cannot find $k$ not deleted cells $(x_1, y_1), (x_2, y_2), \dots, (x_k, y_k)$ that are strictly increasing, i.e., $x_i \lt x_{i+1}$ and $y_i \lt y_{i+1}$ for all $1 \leq i \lt k$.
翻译中…

Your task is to find a solution, or report that it is impossible.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^5$) — the number of test cases. The following lines contain the description of each test case.

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($2 \leq k \leq n \leq 1000$).

翻译中…

Then $n$ lines follow. The $i$-th line contains a binary string $s_i$ of length $n$. The $j$-th character of $s_i$ is 1 if you can delete cell $(i, j)$, and 0 otherwise.

翻译中…

It's guaranteed that the sum of $n^2$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, if there is no way to delete exactly $(n-k+1)^2$ cells to meet the condition, output "NO" (without quotes).

翻译中…

Otherwise, output "YES" (without quotes). Then, output $n$ lines. The $i$-th line should contain a binary string $t_i$ of length $n$. The $j$-th character of $t_i$ is 0 if cell $(i, j)$ is deleted, and 1 otherwise.

翻译中…

If there are multiple solutions, you can output any of them.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

For the first test case, you only have to delete cell $(1, 1)$.

翻译中…

For the second test case, you could choose to delete cells $(1,1)$, $(1,2)$, $(4,3)$ and $(4,4)$.

翻译中…

For the third test case, it is no solution because the cells in the diagonal will always form a strictly increasing sequence of length $5$.

翻译中…

样例

Input #1
4
2 2
10
01
4 3
1110
0101
1010
0111
5 5
01111
10111
11011
11101
11110
5 2
10000
01111
01111
01111
01111
Output #1
YES
01
11
YES
0011
1111
1111
1100
NO
YES
01111
11000
10000
10000
10000
InputCopy OutputCopy
题目信息
题号
1738G
时间限制
2 s
内存限制
512 MB
标签
构造
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。