#include <iostream>
#define ericxiao ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
const int maxN = 2e3 + 326, INF = 2e9 + 326;
int N, M, arr[maxN][maxN], narr[maxN][maxN], mx[maxN][maxN], mn[maxN][maxN], MX = -INF, MN = INF, ans = INF;
inline void rot(){
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++){
narr[j][N - 1 - i] = arr[i][j];
}
swap(N, M);
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) arr[i][j] = narr[i][j];
}
int main(){
ericxiao;
cin >> N >> M;
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++){
cin >> arr[i][j];
MX = max(MX, arr[i][j]);
MN = min(MN, arr[i][j]);
}
for(int jizz = 0; jizz < 4; jizz++){
int _ans = 0;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
mx[i][j] = arr[i][j];
if(i){
mx[i][j] = max(mx[i][j], mx[i - 1][j]);
}
if(j){
mx[i][j] = max(mx[i][j], mx[i][j - 1]);
}
}
}
for(int i = N - 1; i >= 0; i--){
for(int j = M - 1; j >= 0; j--){
mn[i][j] = arr[i][j];
if(i < N - 2){
mn[i][j] = min(mn[i][j], mn[i + 1][j]);
}
if(j < M - 2){
mn[i][j] = min(mn[i][j], mn[i][j + 1]);
}
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
_ans = max(_ans, min(MX - mn[i][j], mx[i][j] - MN));
}
}
ans = min(ans, _ans);
rot();
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
3 ms |
3692 KB |
Output is correct |
16 |
Correct |
8 ms |
4228 KB |
Output is correct |
17 |
Correct |
8 ms |
4204 KB |
Output is correct |
18 |
Correct |
8 ms |
4204 KB |
Output is correct |
19 |
Correct |
8 ms |
4224 KB |
Output is correct |
20 |
Correct |
7 ms |
4204 KB |
Output is correct |
21 |
Correct |
9 ms |
4204 KB |
Output is correct |
22 |
Correct |
11 ms |
4204 KB |
Output is correct |
23 |
Correct |
9 ms |
4204 KB |
Output is correct |
24 |
Correct |
9 ms |
4204 KB |
Output is correct |
25 |
Correct |
12 ms |
4204 KB |
Output is correct |
26 |
Correct |
9 ms |
4204 KB |
Output is correct |
27 |
Correct |
9 ms |
4204 KB |
Output is correct |
28 |
Correct |
9 ms |
4204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
3 ms |
3692 KB |
Output is correct |
16 |
Correct |
8 ms |
4228 KB |
Output is correct |
17 |
Correct |
8 ms |
4204 KB |
Output is correct |
18 |
Correct |
8 ms |
4204 KB |
Output is correct |
19 |
Correct |
8 ms |
4224 KB |
Output is correct |
20 |
Correct |
7 ms |
4204 KB |
Output is correct |
21 |
Correct |
9 ms |
4204 KB |
Output is correct |
22 |
Correct |
11 ms |
4204 KB |
Output is correct |
23 |
Correct |
9 ms |
4204 KB |
Output is correct |
24 |
Correct |
9 ms |
4204 KB |
Output is correct |
25 |
Correct |
12 ms |
4204 KB |
Output is correct |
26 |
Correct |
9 ms |
4204 KB |
Output is correct |
27 |
Correct |
9 ms |
4204 KB |
Output is correct |
28 |
Correct |
9 ms |
4204 KB |
Output is correct |
29 |
Correct |
691 ms |
73516 KB |
Output is correct |
30 |
Correct |
659 ms |
73324 KB |
Output is correct |
31 |
Correct |
754 ms |
73196 KB |
Output is correct |
32 |
Correct |
723 ms |
73196 KB |
Output is correct |
33 |
Correct |
644 ms |
72812 KB |
Output is correct |
34 |
Correct |
737 ms |
73336 KB |
Output is correct |
35 |
Correct |
816 ms |
73356 KB |
Output is correct |
36 |
Correct |
729 ms |
106476 KB |
Output is correct |
37 |
Correct |
852 ms |
112620 KB |
Output is correct |