eolymp
bolt
Try our new interface for solving problems
Problems

The nearest number

The nearest number

Given a matrix \textbf{A} of size \textbf{N}×\textbf{N}, filled with non-negative integers. The distance between the two elements \textbf{A_ij} and \textbf{A_pq} defined as |\textbf{i}-\textbf{p}|+|\textbf{j}-\textbf{q}|. Required to replace each zero element of the nearest non-zero. If there are two or more nearest nonzero cell, zero should be abandoned. \InputFile The first line contains the number \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{200}, \textbf{0} ≤ \textbf{A_ij} ≤ \textbf{1000000}). Then there are \textbf{N} rows of \textbf{N} numbers, separated by spaces that constitute the matrix. \OutputFile Deduced \textbf{N} rows of \textbf{N} numbers, separated by spaces - modified matrix.
Time limit 3 seconds
Memory limit 64 MiB
Input example #1
3
0 0 0
1 0 2
0 3 0
Output example #1
1 0 2
1 0 2
0 3 0