#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
const int INF = 2e9;
int solve(vector<vector<int>> &a) {
int n = sz(a), m = sz(a[0]);
vector<vector<int>> dp1(n, vector<int>(m));
vector<vector<int>> dp2(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp1[i][j] = -a[i][j] + i + j - 1;
dp2[i][j] = a[i][j] + i + j - 1;
if (i != 0) {
dp1[i][j] = max(dp1[i][j], dp1[i - 1][j]);
dp2[i][j] = max(dp2[i][j], dp2[i - 1][j]);
}
if (j != 0) {
dp1[i][j] = max(dp1[i][j], dp1[i][j - 1]);
dp2[i][j] = max(dp2[i][j], dp2[i][j - 1]);
}
}
}
int ans = -INF;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans = max({ans, a[i][j] - i - j + dp1[i][j], -a[i][j] - i - j + dp2[i][j]});
}
}
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
cout << solve(a) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |