#P10612. Laser Box Mirror Arrangement
Laser Box Mirror Arrangement
Laser Box Mirror Arrangement
A mathematician Andris has a small box with an n×m grid on its bottom. In each cell you may place a 45° mirror oriented either as /
or \
. Along the boundary of the box there are 2×(n+m) holes (numbered 1 through 2×(n+m)) through which a light ray can be sent into the box and exit after several reflections.
The holes are numbered as follows:
- Holes 1 to m: along the top edge (from left to right). A ray entering from a top hole enters the grid at row 0 and column (hole number − 1) with initial direction downwards.
- Holes m+1 to m+n: along the right edge (from top to bottom). A ray entering from a right hole enters the grid at row (hole − m − 1) and column m−1 with initial direction leftwards.
- Holes m+n+1 to m+n+m: along the bottom edge (from right to left). A ray entering from a bottom hole enters the grid at row n−1 and column (m − (hole − (m+n))) with initial direction upwards.
- Holes m+n+m+1 to 2×(n+m): along the left edge (from bottom to top). A ray entering from a left hole enters the grid at row (n − (hole − (m+n+m))) and column 0 with initial direction rightwards.
The mirror reflections work as follows:
- If a ray meets a
/
mirror:
• Coming from above (downwards) becomes left,
• Coming from below (upwards) becomes right,
• Coming from the left (rightwards) becomes down,
• Coming from the right (leftwards) becomes up. - If a ray meets a
\
mirror:
• Coming from above (downwards) becomes right,
• Coming from below (upwards) becomes left,
• Coming from the left (rightwards) becomes up,
• Coming from the right (leftwards) becomes down.
Your task is to design a mirror arrangement (i.e. choose /
or \
for each cell) so that for every hole the light ray entering from that hole will exit through a specified designated hole. If no valid configuration exists, output IMPOSSIBLE
.
For example, if Andris wants the light rays entering the 10 holes (which corresponds to a box with n+m=5, e.g. n=1, m=4 or n=2, m=3 etc.) to exit from holes 9, 7, 10, 8, 6, 5, 2, 4, 1, 3 respectively, then the configuration shown in the picture (above) is one valid solution.
Note: It is guaranteed that n and m are small enough for a brute‐force solution to pass.
inputFormat
The first line contains two integers n and m. The second line contains 2×(n+m) integers. The i-th integer specifies the designated exit hole when a ray is shot in from hole i.
Assume that 1 ≤ n, m ≤ 5.
outputFormat
If a valid configuration exists, output n lines, each containing m characters. The j-th character of the i-th line should be either /
or \
, indicating the mirror in that cell. If no configuration exists, output a single line containing IMPOSSIBLE
.
sample
1 1
4 3 2 1
/
</p>