Time limit
2s
Memory limit
128 MB
There is an n x n matrix consisting only of 0s and 1s. The actual matrix has been lost, but the number of 1s in each row and in each column is known.
Consider the matrix below.
| 1 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 0 |
In this matrix, rows 1 through 4 contain 2, 3, 1, and 1 ones, respectively. Columns 1, 2, and 3 each contain 2 ones, and column 4 contains 1 one.
Given the required number of 1s in every row and every column, construct one matrix that satisfies all of them.
The first line contains an integer n. (1 <= n <= 500)
The second line contains n integers: the number of 1s in rows 1 through n, in order.
The third line contains n integers: the number of 1s in columns 1 through n, in order.
Each row or column count is an integer from 0 to n.
If a valid matrix can be constructed, print 1 on the first line. Then print n lines, each containing one row of the matrix as a string of 0s and 1s.
If no valid matrix exists, print -1 on the first line.
If several valid matrices exist, any one of them may be printed.