#include <bits/stdc++.h>
using namespace std;
int h, w, a[1004][1004], mx[1004][1004];
int solve() {
for (int i=0; i<=h; i++) for (int j=0; j<=w; j++) mx[i][j] = -1e8;
int ret = 0;
for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) {
int k = i + j - a[i][j];
mx[i][j] = max({mx[i-1][j], mx[i][j-1], k});
ret = max(ret, mx[i][j] - k - 1);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> h >> w;
for (int i=1; i<=h; i++) for (int j=1; j<=w; j++)
cin >> a[i][j];
int ans = solve();
for (int i=1; i<=h; i++) for (int j=1; j<=w/2; j++) swap(a[i][j], a[i][w-j+1]);
ans = max(ans, solve());
for (int i=1; i<=h/2; i++) for (int j=1; j<=w; j++) swap(a[i][j], a[h-i+1][j]);
ans = max(ans, solve());
for (int i=1; i<=h; i++) for (int j=1; j<=w/2; j++) swap(a[i][j], a[i][w-j+1]);
ans = max(ans, solve());
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
416 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
548 KB |
Output is correct |
2 |
Correct |
2 ms |
644 KB |
Output is correct |
3 |
Correct |
3 ms |
644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
416 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Incorrect |
2 ms |
416 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |