#P10612. [BalticOI 2001] Box of Mirrors

    ID: 12087 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2001Special JudgeBalticOI(波罗的海)

[BalticOI 2001] Box of Mirrors

Problem Description

The mathematician Andris has a small box whose bottom is an n×mn \times m grid. Each cell can contain a mirror oriented at 4545 degrees.

On the boundary of the box, at both ends of every row and every column, there are some holes. Light can enter the box through these holes and can also leave through them.

As shown above, a beam of light entering the box from hole 22 is reflected twice and then leaves from hole 77.

Andris wants you to design a box so that the beam entering from each hole will leave from a specified hole.

For example, if he wants the beams entering from the 1010 holes to leave from holes 9,7,10,8,6,5,2,4,1,39, 7, 10, 8, 6, 5, 2, 4, 1, 3 respectively, then the box shown above also satisfies the requirement.

Note that the holes are numbered from 11 to 2×(n+m)2 \times (n+m) as shown in the figures.

Input Format

The first line contains two integers n,mn, m, representing the size of the box.

In the next 2×(n+m)2 \times (n+m) lines, the (i+1)(i+1)-th line contains an integer aia_i, meaning that the beam entering from hole ii must leave from hole aia_i.

Output Format

Output an n×mn \times m matrix. For each position, output 00 to indicate no mirror is placed, and 11 to indicate a mirror is placed. The output must satisfy the given requirements. The testdata guarantees that a solution always exists.

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

Hint

For 100%100\% of the testdata, 1n,m1001 \leq n, m \leq 100, and 1ai2×(n+m)1 \leq a_i \leq 2 \times (n+m).

Translated by ChatGPT 5