2718: 2501 矩阵距离

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

给定一个N行M列的01矩阵 A,A[i][j] 与 A[k][l] 之间的曼哈顿距离定义为:
dist(A[i][j],A[k][l])=|i-k|+|j-l|

输出一个N行M列的整数矩阵B,其中:
B[i][j]=min(1≤x≤N,1≤y≤M,A[x][y]=1)⁡{dist(A[i][j],A[x][y])}
即求与每个位置曼哈顿距离最近的1
N,M≤1000。

Input

第一行两个整数n,m。

接下来一个N行M列的01矩阵,数字之间没有空格。

Output

一个N行M列的矩阵B,相邻两个整数之间用一个空格隔开。

Sample Input Copy

3 4
0001
0011
0110

Sample Output Copy

3 2 1 0
2 1 0 0
1 0 0 1