CF243E.Matrix
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's consider an n × n square matrix, consisting of digits one and zero.
We'll consider a matrix good, if it meets the following condition: in each row of the matrix all ones go in one group. That is, each row of the matrix looks like that 00...0011...1100...00 (or simply consists of zeroes if it has no ones).
You are given matrix a of size n × n, consisting of zeroes and ones. Your task is to determine whether you can get a good matrix b from it by rearranging the columns or not.
我们考虑一个 n×n 的方阵,其元素仅为数字 0 和 1。
若一个矩阵满足如下条件,则称其为好矩阵:该矩阵的每一行中,所有的 1 都是连续出现的(即构成一个连续的块)。换言之,每一行的形式均为 00…0011…1100…00(若某行不含 1,则整行为全 0)。
现给定一个大小为 n×n 的 0-1 矩阵 a。你的任务是判断:能否通过对矩阵 a 的列进行重排(即仅交换列的位置),得到一个好矩阵 b?
输入格式
The first line contains integer n (1 ≤ n ≤ 500) — the size of matrix a.
Each of n following lines contains n characters "0" and "1" — matrix a. Note that the characters are written without separators.
第一行包含一个整数 n(1≤n≤500)——矩阵 a 的大小。
接下来的 n 行,每行包含 n 个字符 "0" 和 "1" —— 矩阵 a。注意:这些字符之间不使用分隔符。
输出格式
Print "YES" in the first line, if you can rearrange the matrix columns so as to get a good matrix b. In the next n lines print the good matrix b. If there are multiple answers, you are allowed to print any of them.
If it is impossible to get a good matrix, print "NO".
如果可以重新排列矩阵的列,从而得到一个“好”矩阵 b,则在第一行输出 YES;接下来的 n 行输出该“好”矩阵 b。若存在多个可行解,输出任意一个即可。
若无法得到“好”矩阵,则输出 NO。
输入输出样例
输入#1
6 100010 110110 011001 010010 000100 011001
输出#1
YES 011000 111100 000111 001100 100000 000111
输入#2
3 110 101 011
输出#2
NO
输入解题思路,AI测评打分。不知道怎么写?