#Q184. 「一本通 5.5 练习 3」理想的正方形
「一本通 5.5 练习 3」理想的正方形
Description
Original source: HAOI 2007
There is a matrix of integers with dimensions . Your task is to find an square submatrix within it such that the difference between the maximum and minimum values in this submatrix is minimized.
Input Format
The first line contains three integers: , , and ;
The next lines each contain non-negative integers, representing the numbers in the corresponding positions of the matrix.
Output Format
Output a single integer, which is the minimum difference between the maximum and minimum values among all possible square submatrices in the matrix.
Sample 1
5 4 2
1 2 5 6
0 17 16 0
16 17 2 1
2 10 2 1
1 2 2 2
1
Data Range and Hints
For of the data, and ;
For of the data, , , , , and all numbers in the matrix do not exceed .