2137. Box of Mirrors

单点时限: 2.0 sec

内存限制: 256 MB

Mathematician Andris likes different puzzles and one of his favorites is covered box of mirrors. If we look at the horizontal cross-section of such a box, we can see that its basement contains $n \times m$ square cells ($n$ rows, and $m$ columns). In each cell there can be placed mirror which is oriented diagonally from lower left corner to upper right corner. Both sides of the mirror reflect light. At the box edges opposite to each cell row or column there is a gap through which you can light a beam into box or the beam can come out of the box. Through each gap you can light the beam in only one direction–perpendicular to the edge containing the gap. Therefore, beam reflecting from mirror changes its direction by $90$ degrees. When the beam goes through empty cells, its direction doesn’t change. Gaps are numbered consecutively from $1$ to $2(n+m)$, around the box, counter-clockwise, starting from the gap on the left side of the upper left cell and going downwards. Since arrangement of mirrors in the box is not visible, the only way to determine it is by lighting beams in some gaps and watching where light comes out.

Write program that:

  • reads the size of the box and gaps describing beams coming in and out of the box from the input,
  • determines in which cells there are mirrors and which cells are empty,
  • writes the result to the output.

If there are several possible solutions, your program should output anyone of them.

输入格式

First line of input contains two positive integers: $n$ (the number of cells rows, $1 \le n \le 100$) and $m$ (the number of cells columns, $1 \le m \le 100$) separated by a single space. Each of the following $2(n+m)$ lines contains one positive integer. The number in the $i+1$-th line denotes the number of gap from which light comes out if it is lightened into gap number $i$.

输出格式

Your program should write to the output $n$ lines, each of them containing $m$ integers separated by single spaces. The $j$-th number in the $i$-th line should be $1$, if there is a mirror in the cell in the $i$-th row and $j$-th column of the box, or it should be $0$ if the cell is empty.

样例

Input
2 3
9
7
10
8
6
5
2
4
1
3
Output
0 1 0
0 1 1

3 人解决,7 人已尝试。

3 份提交通过,共有 24 份提交。

8.9 EMB 奖励。

创建: 15 年,12 月前.

修改: 6 年,6 月前.

最后提交: 10 月,3 周前.

来源: BOI 2001

题目标签