#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, m;
void swap_up(vector<vector<int>> &a){
vector<vector<int>> b(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
b[i][j] = a[n - i - 1][j];
}
}
a = b;
return;
}
void swap_rl(vector<vector<int>> &a){
vector<vector<int>> b(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
b[i][j] = a[i][m - j - 1];
}
}
a = b;
return;
}
int doit(vector<vector<int>> &a){
int mx = -10;
vector<vector<int>> dp(n + 1, vector<int>(m + 1, -inf));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
// cout << i << ' ' << j << ' ';
dp[i][j] = 0 - a[i - 1][j - 1] + i - 1 + j - 1;
// cout << a[i-1][j-1] << endl;
dp[i][j] = max({dp[i][j], dp[i-1][j], dp[i][j-1]});
mx = max({mx, a[i - 1][j - 1] - i + 1 - j + 1 + dp[i][j] - 1});
}
}
return mx;
}
void solve(){
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];
}
}
int ans = -100;
ans = max(doit(a), ans);
swap_up(a);
ans = max(doit(a), ans);
swap_rl(a);
ans = max(doit(a), ans);
swap_up(a);
ans = max(doit(a), ans);
cout << ans << endl;
}
int main() {
int t = 1;
// cin >> t;
while (t -- ) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |