eolymp
bolt
Try our new interface for solving problems
Problems

Gokigen Naname

Gokigen Naname

\textit{Gokigen Naname} is a Japanese puzzle game played on a square grid in which numbers in circles appear at some of the intersections on the grid. The objective is to draw diagonal lines in each cell of the grid, such that the number in each circle equals the number of lines extending from that circle. Additionally, it is forbidden for the diagonal lines to form an enclosed loop. \includegraphics{https://static.e-olymp.com/content/c7/c7690744803b950916771a85e123fde7ede7e74f.jpg} The first figure shows the start position of a puzzle. The second figure shows the solution to the same puzzle. A Gokigen Naname puzzle always has exactly one solution. \InputFile The first line of the input contains a single integer \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{7}), the number of cells along each of the sides in the square grid. Then follow \textbf{n} + \textbf{1} lines containing the contents of the intersections of the grid cells. Each such line will contain a string of \textbf{n}\textit{ }+ \textbf{1} characters, either a digit between \textbf{0} and \textbf{4}, inclusive, or a period ('.') indicating that there is no number at this intersection (arbitrarily many lines may connect to it). \OutputFile The output should contain \textbf{n} lines, each line containing exactly \textbf{n} characters. Each character should either be a slash or a backslash, denoting how the corresponding grid cell is filled.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
...
.21
.10
Output example #1
//
//
Source 2009 Nordic Collegiate Programming Contest, October 3, Problem F