SPOJ BITMAP

Summary
Within a rectangle, determine the distance from each pixel of said rectangle to the nearest specified pixels.

The input rectangle is provided as a grid of numbers, and a specified pixel is '1' insead of '0'. There is at least one marked pixel.

The distance is the sum of the row and column differences rather than a direct line.

Explanation
based on bfs

Input
1 3 4 0001 0011 0110

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