1104. bitmap

单点时限: 2.0 sec

内存限制: 256 MB

There is given a rectangular bitmap of size n*m. Each pixel of the bitmap is either white or black, but at least one is white. The pixel in i-th line and j-th column is called the pixel (i,j). The distance between two pixels p1=(i1,j1) and p2=(i2,j2) is defined as:

d(p1,p2)=|i1-i2|+|j1-j2|.

Task

Write a program which:

reads the description of the bitmap,

for each pixel, computes the distance to the nearest white pixel,

writes the results

输入格式

In the first line there is a pair of integer numbers n, m separated by a single space, 1<=n <=182, 1<=m<=182. In each of the following n lines exactly one zero-one word of length m, the description of one line of the bitmap, is written. On the j-th position in the line (i+1), 1 <= i <= n, 1 <= j <= m, is ‘1’ if, and only if the pixel (i,j) is white.

输出格式

In the i-th line of the output, 1<=i<=n, there should be written m integers f(i,1),…,f(i,m) separated by single spaces, where f(i,j) is the distance from the pixel (i,j) to the nearest white pixel.

样例

Input
3 4
0001
0011
0110
Output
3 2 1 0
2 1 0 0
1 0 0 1

21 人解决,42 人已尝试。

31 份提交通过,共有 160 份提交。

6.1 EMB 奖励。

创建: 16 年,9 月前.

修改: 6 年,8 月前.

最后提交: 9 月,3 周前.

来源: POI 1999 II Stage

题目标签