406477: GYM102419 J Jaber The policeman

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Jaber The policemantime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Jaber is a policeman of a city that can be described by a grid of size $$$n \times m$$$, where every cell in that grid contains a house of one of the civilians.

At night every person in the city should go sleep and should turn the lights of their house off.

As a policeman Jaber should check the lights of every house in that city.

Jaber checks every row and every column in that city exactly once, in the order written on a paper with Jaber.

Every time Jaber checks a row or a column, he counts the number of houses that has their lights turned on. If he found more than one house with lights turned on he becomes sad.

Also every time he checks a row or a column, he makes sure that every house in that row or column will turn off their lights.

Ayoub doesn't remember exactly the description of the city, but he remembers in every row the number of houses that will have their lights on.

Ayoub wants to know if it is possible to have a city with that description and has at least one correct order.

Input

The first line contains two integers $$$n$$$ and $$$m$$$ $$$(1 \leq n , m \leq 1000)$$$.

The second line contains $$$n$$$ integers, the $$$i_{th}$$$ one is $$$a_i$$$ $$$(0 \leq a_i \leq m)$$$, which is the number of houses that will have their lights on in the $$$i_{th}$$$ row.

Output

If there is no possible answer print NO on a line, otherwise print YES.

if there is an answer you should print $$$n$$$ lines, the $$$i_{th}$$$ line should contain $$$m$$$ characters, the $$$j_{th}$$$ character should be 1 if the house in the $$$i_{th}$$$ row $$$j_{th}$$$ column has their lights on, and 0 otherwise.

make sure that the number of 1's in the $$$i_{th}$$$ row is equal to $$$a_i$$$.

then you should print $$$n + m$$$ lines, which is a correct order of rows and columns that won't make Jaber sad.

in every line you should print

row $$$x$$$ or col $$$x$$$.

make sure that every row and column appears exactly once.

ExamplesInput
4 4
1 0 0 0
Output
YES
1000
0000
0000
0000
row 1
col 1
row 2
col 2
row 3
col 3
row 4
col 4
Input
4 4
2 1 1 1
Output
YES
1010
1000
0100
0001
col 3
row 1
col 1
row 2
col 2
row 3
row 4
col 4

Source/Category

加入题单

算法标签: