Description
Give a n*n map, each lattice has a price, find a rectangular area so that its price sum is located in [k,2k]
Input
Enter K N (n<2000) and a map of n*n
Output
The upper-left and lower-right columns of the output rectangle-line coordinates or NIE
Sample Input
4 3
1 1 1
1 9 1
1 1 1
inputdata2
1 2 1 3
25 1 2 1
4 3 3
3 2
Sample Output
Outputdata1
NIE
Outputdata2
2 1 4 2
The puzzle (from the author):
If there is a[i,j]∈[k,2k] direct output. Otherwise, the point of a[i,j]>2k is regarded as an obstacle, and a recursive f[i,j] means that there is no obstacle in the continuous section from I,j to left, and similar g[i,j] indicates the length to the right. Because of the a[i,j]<k, the neighboring prefixes and the impossibility from <k into >2k. So if there is s[i,l. R]>2K is bound to exist s[i,l. P]∈[K,2K], the F value is determined if there is s[i,j-f[i,j]+1..j]∈[k,2k]. Otherwise we use f and g to find the maximal and sub-matrix Smax (classical algorithm, not repeat). If the smax<k is no solution, otherwise there must be Smax prefix and ∈[k,2k].
[BZOJ1127] [POI2008] Kup Sub-matrix