eolymp
bolt
Try our new interface for solving problems
Problems

Lines (2)

Lines (2)

In the table of \textbf{N} rows and \textbf{N} columns, some cells are occupied by beads, others are free. Selected ball, you want to move, and wherever it moved. Selected ball at each step moves to the next horizontally or vertically free cell. Required to determine whether it is possible to move the ball from the initial cells in a given, and if possible, find a way out of the fewest steps. \InputFile The first line contains the number \textbf{N} (2 ≤\textbf{ N }≤\textbf{ 250}), the following \textbf{N} lines - on \textbf{N} symbols. The symbol denotes the point of free cells, the Latin capital \textbf{O} - Ball, \textbf{@} - initial position the ball, which should move the Latin title \textbf{X} - end position of the ball. \OutputFile The first line of output \textbf{Y}, if the motion is possible, or \textbf{N}, if not. If further movement is possible should abstain \textbf{N} lines of \textbf{N} characters - as well as the input, but \textbf{X}, as well as all points along the path are replaced with positives.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5
....X
.OOOO
.....
OOOO.
@....
Output example #1
Y
+++++
+OOOO
+++++
OOOO+
@++++