QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#16157. Bitmap

统计

We are given an $n \times m$ monochrome bitmap, which contains at least one white pixel. We denote the pixel at the $i$-th row and $j$-th column as $(i, j)$, and define the distance between two points $p_1=(i_1, j_1)$ and $p_2=(i_2, j_2)$ as: $$d(p_1, p_2)=|i_1 - i_2| + |j_1 - j_2|$$

For each pixel, calculate the distance to the nearest white pixel.

Input

The first line contains two space-separated integers $n$ and $m$, where $1 \le n \le 182$ and $1 \le m \le 182$. The following $n$ lines each contain a string of length $m$ consisting of $0$s and $1$s. If the $j$-th character in the $i$-th line is "1", it means the pixel $(i, j)$ is white; otherwise, it is black.

Output

Output an $n \times m$ table of numbers, where the $j$-th number in the $i$-th row is $f(i, j)$, representing the distance from pixel $(i, j)$ to the nearest white pixel.

Examples

Input 1

3 4
0001
0011
0110

Output 1

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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.