Bitmap
Time limit1sMemory limit128 MB
For each black pixel in an n by m bitmap, output the Manhattan distance to the closest white pixel.
- Level
Medium5 of 10
- Topics
- BFS, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
You are given a rectangular bitmap of size . Each pixel of the bitmap is either white or black, and at least one pixel is white. The pixel in row and column is denoted .
The distance between two pixels and is defined as
Write a program that, for every pixel, computes the distance to the nearest white pixel.
Input
The first line contains two integers and separated by a single space (, ).
Each of the following lines contains one string of length made of the characters 0 and 1, describing one row of the bitmap. In the string that describes row of the bitmap, the -th character is 1 if and only if the pixel is white (, ).
Output
Print lines. The -th line must contain integers separated by single spaces, where is the distance from the pixel to the nearest white pixel.