#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
const int INF = 2e9;
int n, m;
int arr[MAXN+1][MAXN+1];
int pre[MAXN+1][MAXN+1];
int ans;
void rotate(int n, int m) {
for (int i = 1; i <= max(n,m); i++)
for (int j = i+1; j <= max(n,m); j++)
swap(arr[i][j], arr[j][i]);
for (int i = 1; i <= m; i++)
for(int j = 1; j <= n/2; j++)
swap(arr[i][j], arr[i][n-j+1]);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> arr[i][j];
for (int i = 0; i <= max(n,m); i++)
pre[i][0] = INF;
for (int i = 0; i <= max(n,m); i++)
pre[0][i] = INF;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
pre[i][j] = min({pre[i-1][j], pre[i][j-1], arr[i][j]-i-j});
ans = max({ans, arr[i][j]-i-j - pre[i-1][j], arr[i][j]-i-j - pre[i][j-1]});
}
}
rotate(n, m);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
pre[i][j] = min({pre[i-1][j], pre[i][j-1], arr[i][j]-i-j});
ans = max({ans, arr[i][j]-i-j - pre[i-1][j], arr[i][j]-i-j - pre[i][j-1]});
}
}
rotate(m, n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
pre[i][j] = min({pre[i-1][j], pre[i][j-1], arr[i][j]-i-j});
ans = max({ans, arr[i][j]-i-j - pre[i-1][j], arr[i][j]-i-j - pre[i][j-1]});
}
}
rotate(n, m);
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
pre[i][j] = min({pre[i-1][j], pre[i][j-1], arr[i][j]-i-j});
ans = max({ans, arr[i][j]-i-j - pre[i-1][j], arr[i][j]-i-j - pre[i][j-1]});
}
}
cout << ans-1 << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8192 KB |
Output is correct |
2 |
Correct |
8 ms |
8192 KB |
Output is correct |
3 |
Correct |
8 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
1 ms |
768 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
8 ms |
8192 KB |
Output is correct |
10 |
Correct |
8 ms |
8192 KB |
Output is correct |
11 |
Correct |
8 ms |
8192 KB |
Output is correct |
12 |
Correct |
1 ms |
768 KB |
Output is correct |
13 |
Correct |
1 ms |
768 KB |
Output is correct |
14 |
Correct |
1 ms |
768 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
1 ms |
768 KB |
Output is correct |
17 |
Correct |
1 ms |
768 KB |
Output is correct |
18 |
Correct |
137 ms |
9460 KB |
Output is correct |
19 |
Correct |
137 ms |
16760 KB |
Output is correct |
20 |
Correct |
135 ms |
16504 KB |
Output is correct |
21 |
Correct |
141 ms |
16632 KB |
Output is correct |
22 |
Correct |
142 ms |
16632 KB |
Output is correct |
23 |
Correct |
140 ms |
16632 KB |
Output is correct |
24 |
Correct |
138 ms |
17400 KB |
Output is correct |