Diagonals is a pencil puzzle which is played on a square grid. The player must draw a diagonal line corner to corner in every cell in the grid, either top left to bottom right, or bottom left to top right. There are two constraints:
Some intersections of gridlines have a number from 0 to 4 inclusive on them, which is the exact number of diagonals that must touch that point.
No set of diagonals may form a loop of any size or shape.
The following is a 5 X 5 example, with its unique solution:
Given the numbers at the intersections of a grid, solve the puzzle.
The first line of input contains an integer n (1 ≤ n ≤ 8), which is the size of the grid.
Each of the next n+1 lines contains a string s (|s|=n+1, s ∈ {0, 1, 2, 3,4, +}*). These are the intersections of the grid, with '+' indicating that there is no number at that intersection.
The input data will be such that the puzzle has exactly one solution.
Output exactly $n$ lines, each with exactly $n$ characters, representing the solution to the puzzle. Each character must be either '/' or '\'.
Note that Sample 1 corresponds to the example in the problem description.
Sample Input 1 | Sample Output 1 |
---|---|
5 +1+2++ 1++11+ +3+2++ 02+++1 ++3+1+ +1+++1 |
\\/\\ \/\\/ \\\\\ ////\ //\\\ |
Sample Input 2 | Sample Output 2 |
---|---|
3 ++++ +1+1 +31+ +0+0 |
/\/ /// /\/ |
Sample Input 3 | Sample Output 3 |
---|---|
4 +++++ +3++2 ++3++ +3+3+ ++2+0 |
\//\ \\// \\\/ /\// |