CF1157G.Inverse of Rows and Columns

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a binary matrix aa of size n×mn \times m. A binary matrix is a matrix where each element is either 00 or 11.

You may perform some (possibly zero) operations with this matrix. During each operation you can inverse the row of this matrix or a column of this matrix. Formally, inverting a row is changing all values in this row to the opposite (00 to 11, 11 to 00). Inverting a column is changing all values in this column to the opposite.

Your task is to sort the initial matrix by some sequence of such operations. The matrix is considered sorted if the array [a1,1,a1,2,…,a1,m,a2,1,a2,2,…,a2,m,…,an,m−1,an,m][a_{1, 1}, a_{1, 2}, \dots, a_{1, m}, a_{2, 1}, a_{2, 2}, \dots, a_{2, m}, \dots, a_{n, m - 1}, a_{n, m}] is sorted in non-descending order.

给你一个大小为 n×mn \times m 的二进制矩阵 aa。二进制矩阵是指其中每个元素均为 00 或 11 的矩阵。

你可以对该矩阵执行若干次(可能为零次)操作。每次操作可选择翻转该矩阵的一行或一列。形式上,翻转一行是指将该行中所有元素取反(即 00 变为 11,11 变为 00);翻转一列是指将该列中所有元素取反。

你的任务是通过若干次上述操作,将初始矩阵变为“已排序”状态。当数组

[a1,1,a1,2,…,a1,m,a2,1,a2,2,…,a2,m,…,an,m−1,an,m][a_{1, 1}, a_{1, 2}, \dots, a_{1, m}, a_{2, 1}, a_{2, 2}, \dots, a_{2, m}, \dots, a_{n, m - 1}, a_{n, m}]

按非降序排列时,称该矩阵为已排序。

输入格式

The first line of the input contains two integers nn and mm (1≤n,m≤2001 \le n, m \le 200) — the number of rows and the number of columns in the matrix.

The next nn lines contain mm integers each. The jj-th element in the ii-th line is ai,ja_{i, j} (0≤ai,j≤10 \le a_{i, j} \le 1) — the element of aa at position (i,j)(i, j).

输入的第一行包含两个整数 nn 和 mm(1≤n,m≤2001 \le n, m \le 200)—— 分别表示矩阵的行数和列数。

接下来的 nn 行,每行包含 mm 个整数。第 ii 行的第 jj 个元素为 ai,ja_{i, j}(0≤ai,j≤10 \le a_{i, j} \le 1)—— 即矩阵 aa 在位置 (i,j)(i, j) 处的元素。

输出格式

If it is impossible to obtain a sorted matrix, print "NO" in the first line.

Otherwise print "YES" in the first line. In the second line print a string rr of length nn. The ii-th character rir_i of this string should be '1' if the ii-th row of the matrix is inverted and '0' otherwise. In the third line print a string cc of length mm. The jj-th character cjc_j of this string should be '1' if the jj-th column of the matrix is inverted and '0' otherwise. If there are multiple answers, you can print any.

如果无法得到一个有序矩阵,则在第一行输出 "NO"。

否则,在第一行输出 "YES";在第二行输出一个长度为 nn 的字符串 rr,其中第 ii 个字符 rir_i 为 '1' 表示矩阵的第 ii 行被翻转,为 '0' 表示未翻转;在第三行输出一个长度为 mm 的字符串 cc,其中第 jj 个字符 cjc_j 为 '1' 表示矩阵的第 jj 列被翻转,为 '0' 表示未翻转。若存在多个可行解,输出任意一个即可。

输入输出样例

  • 输入#1

    2 2
    1 1
    0 1

    输出#1

    YES
    00
    10
  • 输入#2

    3 4
    0 0 0 1
    0 0 0 0
    1 1 1 1

    输出#2

    YES
    010
    0000
  • 输入#3

    3 3
    0 0 0
    1 0 1
    1 1 0

    输出#3

    NO

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

首页