CF1738G.Anti-Increasing Addicts

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an n×nn \times n grid.

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

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

  • You cannot find kk not deleted cells (x1,y1),(x2,y2),…,(xk,yk)(x_1, y_1), (x_2, y_2), \dots, (x_k, y_k) that are strictly increasing, i.e., xi<xi+1x_i \lt x_{i+1} and yi<yi+1y_i \lt y_{i+1} for all 1≤i<k1 \leq i \lt k.

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

给你一个 n×nn \times n 的网格。

我们用 (i,j)(i, j) 表示第 ii 行、第 jj 列的格子。对每个格子,你已知它是否可以被删除。

给定一个整数 kk,你需要恰好删除 (n−k+1)2(n-k+1)^2 个格子,使得满足以下条件:

  • 不存在 kk 个未被删除的格子 (x1,y1),(x2,y2),…,(xk,yk)(x_1, y_1), (x_2, y_2), \dots, (x_k, y_k),它们是严格递增的,即对所有 1≤i<k1 \leq i < k,均有 xi<xi+1x_i < x_{i+1} 且 yi<yi+1y_i < y_{i+1}。

你的任务是找出一种可行方案,或判定其不可能。

输入格式

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1051 \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 nn and kk (2≤k≤n≤10002 \leq k \leq n \leq 1000).

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

It's guaranteed that the sum of n2n^2 over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5),表示测试用例的数量。接下来的若干行描述每个测试用例。

每个测试用例的第一行包含两个整数 nn 和 kk(2≤k≤n≤10002 \leq k \leq n \leq 1000)。

随后是 nn 行。第 ii 行包含一个长度为 nn 的二进制字符串 sis_i。sis_i 的第 jj 个字符为 1 表示可以删除单元格 (i,j)(i, j),为 0 表示不可删除。

保证所有测试用例中 n2n^2 的总和不超过 10610^6。

输出格式

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

Otherwise, output "YES" (without quotes). Then, output nn lines. The ii-th line should contain a binary string tit_i of length nn. The jj-th character of tit_i is 0 if cell (i,j)(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).

对于每个测试用例,若不存在恰好删除 (n−k+1)2(n-k+1)^2 个格子以满足条件的方法,则输出 "NO"(不带引号)。

否则,输出 "YES"(不带引号)。然后,输出 nn 行。第 ii 行应包含一个长度为 nn 的二进制字符串 tit_i。其中 tit_i 的第 jj 个字符为 0 表示格子 (i,j)(i, j) 被删除,为 1 表示未被删除。

若存在多种解法,输出任意一种即可。

"YES" 和 "NO" 的大小写不限(例如,字符串 "yEs"、"yes" 和 "Yes" 均会被识别为肯定回答)。

输入输出样例

  • 输入#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

    输出#1

    YES
    01
    11
    YES
    0011
    1111
    1111
    1100
    NO
    YES
    01111
    11000
    10000
    10000
    10000

说明/提示

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

For the second test case, you could choose to delete cells (1,1)(1,1), (1,2)(1,2), (4,3)(4,3) and (4,4)(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 55.

对于第一个测试用例,你只需删除单元格 (1,1)(1, 1)。

对于第二个测试用例,你可以选择删除单元格 (1,1)(1,1)、(1,2)(1,2)、(4,3)(4,3) 和 (4,4)(4,4)。

对于第三个测试用例,不存在解,因为对角线上的单元格将始终构成一个长度为 55 的严格递增序列。

输入解题思路,AI测评打分。不知道怎么写?

首页