#P15657. [ICPC 2025 Jakarta R] Binary Grid

[ICPC 2025 Jakarta R] Binary Grid

题目描述

You are given an array AA containing NN non-negative integers. You have to construct a binary grid of size N×MN \times M such that:

  • for any cell with value 11, any of its adjacent cells, i.e. cells that share one of its four sides, must not\textbf{not} have the value 11.
  • the number of cells with value 11 in row ii is exactly AiA_i.

Find any such binary grid or tell that it's impossible to construct.

输入格式

The first line contains two integers NN and MM (1N,M10001 \leq N, M \leq 1000).

The next line contains NN integers containing AiA_i (0AiM0 \leq A_i \leq M).

输出格式

Output NN lines, each containing MM characters of either 0\texttt{0} or 1\texttt{1} representing the binary grid you constructed. If multiple construction exists, you may output any of them. If such a grid does not exist, output 1-1.

6 7
4 3 2 2 3 4
1010101
0101010
1010000
0000101
0101010
1010101
2 2
2 2
-1