#P15031. [UOI 2021 II Stage] 矩阵
[UOI 2021 II Stage] 矩阵
Problem Description
Cossack Beard got a matrix of size by (that is, a matrix with rows and columns). The elements of this matrix are only and .
Someone introduced Cossack to the Manhattan distance between elements in a matrix. It turns out that if one element is in row and column , and another element is in row and column , then the Manhattan distance between these two elements is defined as (the sum of the absolute values of the coordinate differences).
After that, Beard understood that the "beauty" of any element in the matrix is the distance from that element to the nearest element with value . Note that the "beauty" of any is . Also, Cossack learned that in such a matrix, there is at least one .
Your task is simple: find the "beauty" of the most "beautiful" element in the matrix.
Input Format
The first line contains two integers and , the number of rows and columns of the matrix.
The next lines each contain digits , the values of the matrix elements.
It is guaranteed that there is at least one .
Output Format
Output one number, the maximum "beauty".
2 3
010
000
2
3 4
0101
0001
0000
3
Hint
Sample Explanation
For the matrix in the first sample, write the "beauty" of each element in matrix form:
:::align{center} 1 0 1
2 1 2 :::
As we can see, there are two matrix elements, (row , column ) and (row , column ), that have the maximum "beauty", which is .
For the second sample, its "beauty" matrix is:
:::align{center} 1 0 1 0
2 1 1 0
3 2 2 1 :::
Scoring Rules
A solution that works correctly under the constraint will get at least points.
A solution that works correctly under the constraint will get at least points.
The translation was completed by DeepSeek V3.
Translated by ChatGPT 5