#P10063. [CF243E]Matrix

[CF243E]Matrix

Matrix

题面翻译

给出一个n*n的01矩阵,问能否交换矩阵中各列,使得每一行的1全部连续,如果可以,输出YES,然后输出交换后任意一个可能的结果,否则,输出NO

题目描述

Let's consider an n×n 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 00...0011...1100...00 (or simply consists of zeroes if it has no ones).

You are given matrix a a of size n×n n×n , consisting of zeroes and ones. Your task is to determine whether you can get a good matrix b b from it by rearranging the columns or not.

输入格式

The first line contains integer n n ( 1<=n<=500 1<=n<=500 ) — the size of matrix a a .

Each of n n following lines contains n n characters "0" and "1" — matrix a a . Note that the characters are written without separators.

输出格式

Print "YES" in the first line, if you can rearrange the matrix columns so as to get a good matrix b b . In the next n n lines print the good matrix b 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".

样例 #1

样例输入 #1

6
100010
110110
011001
010010
000100
011001

样例输出 #1

YES

样例 #2

样例输入 #2

3

样例输出 #2

NO

Hint

原题还要求输出方案,可以想一下怎么做