Problem L
Lasers
Consider a grid of $n$ columns and $m$ rows. Number the columns from $0$ to $n-1$ from left to right.
Within the grid, some double-sided mirrors of the form “\” or “/” are placed.
Assume the grid wraps around, that is, the left edge is connected to the right edge.
When a laser is shined from the top, it will travel down the grid and might get reflected through the mirrors. For example:
In the example above, the laser ray entering column $2$ from the top travels out at column $4$ at the bottom.
Given an integer $n$ and a permutation $p = (p_0, p_1, \dots , p_{n-1})$ of $\{ 0, 1, \dots , n-1 \} $. Find a grid with the minimum nonnegative number of rows $m$, such that for every $i = 0, \dots , n-1$, the laser entering column $i$ from the top will travel out at column $p_ i$ at the bottom.
Input
There will be multiple test cases, terminated by EOF.
For each test case: The first line contains a positive integer $n$, the second line contains $n$ space-separated integers, $p_0\ p_1\ \dots \ p_ n$.
Output
For each test case, print the number of rows $m$ on the first line. The $m$ subsequent lines should contain the mirror configurations of each row, using character “\”, “/” or “.” (without quotes) to represent each cell.
For example, the image above corresponding to the following output:
3 \.../ \./.. .../.
If there are multiple possible configurations, output any of them.
Limits
Each file has at least one test case.
The sum of $n$ for each file does not exceed $10^4$.
The output file size does not exceed $5 \cdot 10^6$ bytes.
Sample Input 1 | Sample Output 1 |
---|---|
1 0 5 1 2 3 4 0 8 1 0 3 2 5 4 7 6 |
0 1 \\\\\ 2 ././././ \\\\\\\\ |