atcoder#AGC038A. [AGC038A] 01 Matrix
[AGC038A] 01 Matrix
Score : points
Problem Statement
We have a square grid with rows and columns. Snuke wants to write or in each of the squares. Here, all of the following conditions have to be satisfied:
- For every row, the smaller of the following is : the number of s contained in the row, and the number of s contained in the row. (If these two numbers are equal, “the smaller” should be read as “either”.)
- For every column, the smaller of the following is : the number of s contained in the column, and the number of s contained in the column.
Determine if these conditions can be satisfied by writing or in each of the squares. If the answer is yes, show one way to fill the squares so that the conditions are satisfied.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the conditions cannot be satisfied by writing or in each of the squares, print .
If the conditions can be satisfied, print one way to fill the squares so that the conditions are satisfied, in the following format:
Here is the digit written in the square at the -th row from the top and the -th column from the left in the grid.
If multiple solutions exist, printing any of them will be accepted.
3 3 1 1
100
010
001
Every row contains two s and one , so the first condition is satisfied. Also, every column contains two s and one , so the second condition is satisfied.
1 5 2 0
01010