Problem C

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\! \times \! 5$ example, with its unique solution:

\includegraphics[width=0.75\textwidth ]{diagonals.pdf}

Given the numbers at the intersections of a grid, solve the puzzle.


The first line of input contains an integer $n$ ($1 \le n \le 8$), which is the size of the grid.

Each of the next $n+1$ lines contains a string $s$ ($|s|=n+1, s \in \{ \texttt{0},\texttt{1},\texttt{2},\texttt{3},\texttt{4},\texttt{+}\} ^*$). 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
Sample Input 2 Sample Output 2
Sample Input 3 Sample Output 3

Please log in to submit a solution to this problem

Log in