| 2026 Spring UT CS104c Midterm #2 |
|---|
| Finished |
While bored in class, your friend doodled an $$$N \times N$$$ grid of binary digits 0 and 1. She then computed the sum of each row and column.
You wonder: knowing these row and column sums, can you construct a grid of binary digits whose rows and columns have those sums? (There might not be a unique answer, so your grid doesn't have to exactly match your friend's original grid.)
The first line of input contains a single integer $$$N$$$ $$$(1 \leq N \leq 8)$$$, the size of the grid you need to construct.
The second line contains $$$N$$$ space-separated integers $$$c_i$$$ $$$(0 \leq c_i \leq N)$$$, the sums of the columns of the grid, in order from left to right.
The last line contains $$$N$$$ space-separated integers $$$r_i$$$ $$$(0 \leq r_i \leq N$$$), the sums of the rows of the grid, in order from top to bottom.
It is guaranteed that the $$$r_i$$$ and $$$c_i$$$ were computed from an $$$N\times N$$$ grid of binary digits.
Print $$$N$$$ lines of exactly $$$N$$$ 0 or 1 characters each: a grid whose row and column sums match the sums in the input. If there are multiple possible such grids, you may print any one of them.
41 0 1 00 1 1 0
0000 0010 1000 0000
100
0
85 3 3 4 3 3 2 34 4 1 3 6 2 4 2
00001111 00001111 00000001 10110000 11111100 10010000 11110000 11000000
| Name |
|---|


