#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll grid[1001][1001], val[1001][1001][4], mn[1002][1002][4];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> grid[i][j];
val[i][j][0] = grid[i][j] - i - j + 1;
val[i][j][1] = grid[i][j] - m + j - i;
val[i][j][2] = grid[i][j] + i + j - 1;
val[i][j][3] = grid[i][j] + m - j + i;
}
ll ans = 0;
memset(mn, 0x3f, sizeof mn);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
mn[i][j][0] = min({val[i][j][0], mn[i - 1][j][0], mn[i][j - 1][0]});
ans = max(ans, val[i][j][0] - mn[i][j][0]);
}
for (int i = 1; i <= n; i++)
for (int j = m; j; j--) {
mn[i][j][1] = min({val[i][j][1], mn[i - 1][j][1], mn[i][j + 1][1]});
ans = max(ans, val[i][j][1] - mn[i][j][1]);
}
for (int i = n; i; i--)
for (int j = m; j; j--) {
mn[i][j][2] = min({val[i][j][2], mn[i + 1][j][2], mn[i][j + 1][2]});
ans = max(ans, val[i][j][2] - mn[i][j][2]);
}
for (int i = n; i; i--)
for (int j = 1; j <= m; j++) {
mn[i][j][3] = min({val[i][j][3], mn[i + 1][j][3], mn[i][j - 1][3]});
ans = max(ans, val[i][j][3] - mn[i][j][3]);
}
cout << ans - 1;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
31692 KB |
Output is correct |
2 |
Correct |
14 ms |
31736 KB |
Output is correct |
3 |
Correct |
14 ms |
31692 KB |
Output is correct |
4 |
Correct |
13 ms |
31680 KB |
Output is correct |
5 |
Correct |
14 ms |
31684 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
14 ms |
31720 KB |
Output is correct |
8 |
Correct |
14 ms |
31692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
31820 KB |
Output is correct |
2 |
Correct |
15 ms |
31732 KB |
Output is correct |
3 |
Correct |
14 ms |
31780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
31692 KB |
Output is correct |
2 |
Correct |
14 ms |
31736 KB |
Output is correct |
3 |
Correct |
14 ms |
31692 KB |
Output is correct |
4 |
Correct |
13 ms |
31680 KB |
Output is correct |
5 |
Correct |
14 ms |
31684 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
14 ms |
31720 KB |
Output is correct |
8 |
Correct |
14 ms |
31692 KB |
Output is correct |
9 |
Correct |
15 ms |
32204 KB |
Output is correct |
10 |
Correct |
14 ms |
32220 KB |
Output is correct |
11 |
Correct |
14 ms |
32288 KB |
Output is correct |
12 |
Correct |
15 ms |
32204 KB |
Output is correct |
13 |
Correct |
14 ms |
32204 KB |
Output is correct |
14 |
Correct |
15 ms |
32204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
31692 KB |
Output is correct |
2 |
Correct |
14 ms |
31736 KB |
Output is correct |
3 |
Correct |
14 ms |
31692 KB |
Output is correct |
4 |
Correct |
13 ms |
31680 KB |
Output is correct |
5 |
Correct |
14 ms |
31684 KB |
Output is correct |
6 |
Correct |
14 ms |
31692 KB |
Output is correct |
7 |
Correct |
14 ms |
31720 KB |
Output is correct |
8 |
Correct |
14 ms |
31692 KB |
Output is correct |
9 |
Correct |
16 ms |
31820 KB |
Output is correct |
10 |
Correct |
15 ms |
31732 KB |
Output is correct |
11 |
Correct |
14 ms |
31780 KB |
Output is correct |
12 |
Correct |
15 ms |
32204 KB |
Output is correct |
13 |
Correct |
14 ms |
32220 KB |
Output is correct |
14 |
Correct |
14 ms |
32288 KB |
Output is correct |
15 |
Correct |
15 ms |
32204 KB |
Output is correct |
16 |
Correct |
14 ms |
32204 KB |
Output is correct |
17 |
Correct |
15 ms |
32204 KB |
Output is correct |
18 |
Correct |
164 ms |
79472 KB |
Output is correct |
19 |
Correct |
163 ms |
79428 KB |
Output is correct |
20 |
Correct |
157 ms |
79024 KB |
Output is correct |
21 |
Correct |
163 ms |
79428 KB |
Output is correct |
22 |
Correct |
169 ms |
79472 KB |
Output is correct |
23 |
Correct |
161 ms |
79428 KB |
Output is correct |
24 |
Correct |
162 ms |
78276 KB |
Output is correct |