Sign
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Given a table with N rows and M columns, where each cell contains either a 0 or a 1. The distance between two cells, (x_1, y_1) and (x_2, y_2), is defined as the sum |x_1-x_2| + |y_1-y_2|. Your task is to create a new table where each cell (i, j) contains the minimum distance from that cell in the original table to any cell containing a 1. It is guaranteed that there is at least one 1 in the table.
Input
The first line of the input contains two natural numbers N and M, each not exceeding 100. The next N lines contain M numbers each, representing the elements of the table.
Output
The output should consist of N rows with M numbers each, representing the elements of the constructed table.
Examples
Input #1
Answer #1
Submissions 1K
Acceptance rate 45%