#P1256. 显示图像
显示图像
Description
An old display screen consists of pixels. The position of a pixel is determined by its row and column. For example, denotes the pixel at row , column . At that time, the screen could only show two colors, black and white, represented by binary and . denotes black and denotes white. When the computer issues an instruction , the cathode ray tube at row , column on the screen starts working, making that pixel display white; if , then the corresponding cathode ray tube does not work, and the pixel remains black. At a certain moment, the computer issues a command for the entire screen in the form of an two-dimensional matrix.
For example, the screen consists of pixels. At some moment, the computer issues the following command:
$$\begin{pmatrix} 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 1 \\ 0 & 1 & 1 & 0 \\ \end{pmatrix}$$The corresponding screen display should be:

Assume that after magnification, one cell represents one pixel.
For unknown reasons, black pixels are always affected by white pixels—possibly due to the operation of the cathode ray tube. Moreover, the closer the distance, the greater the influence. The distance is defined as follows:
Given pixel and pixel , their distance is .
At a certain moment after the display command is issued, scientists want to know, for each pixel, the shortest distance to its nearest white pixel—scientists guarantee that there is at least one white pixel on the screen.
In the example above, the distance between pixel and its nearest white pixel is , while pixel itself is white, so the shortest distance is .
Input Format
The first line contains two numbers, and , indicating the screen size.
The next lines each contain numbers, or . This is the display command issued by the computer.
Output Format
Output lines, each containing numbers separated by a single space. The number in row , column indicates the shortest distance from pixel to its nearest white pixel.
3 4
0001
0011
0110
3 2 1 0
2 1 0 0
1 0 0 1
Hint
- For of the testdata: .
- For of the testdata: .
Translated by ChatGPT 5
京公网安备 11011102002149号