Submission #1235801

#TimeUsernameProblemLanguageResultExecution timeMemory
1235801AishaMaxcomp (info1cup18_maxcomp)C++20
100 / 100
235 ms31904 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define ff first #define ss second int sol(vector <vector <int>> a) { int n = a.size() - 1; int m = a[0].size() - 1; int ans = -1; vector <vector <int>> dp1(n + 1, vector <int> (m + 1)); vector <vector <int>> dp2(n + 1, vector <int> (m + 1)); dp1[1][1] = a[1][1] + 1 + 1; dp2[1][1] = a[1][1] - 1 - 1; for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { dp1[i][j] = a[i][j] + i + j; dp2[i][j] = a[i][j] - i - j; if (j != 1) dp1[i][j] = max(dp1[i][j], dp1[i][j - 1]); if (i != 1) dp1[i][j] = max(dp1[i][j], dp1[i - 1][j]); if (j != 1) dp2[i][j] = min(dp2[i][j], dp2[i][j - 1]); if (i != 1) dp2[i][j] = min(dp2[i][j], dp2[i - 1][j]); // cout << i << ' ' << j << ' ' << dp1[i][j] << ' ' << dp2[i][j] << endl; // cout << dp1[i][j] - a[i][j] - i - j - 1 << endl; // cout << a[i][j] - i - j - dp2[i][j] - 1 << endl; ans = max({ans, dp1[i][j] - a[i][j] - i - j - 1, a[i][j] - i - j - dp2[i][j] - 1}); } } /* for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) { for (int x = 1; x <= i; x ++) { for (int y = 1; y <= j; y ++) { int s = abs(a[i][j] - a[x][y]) - (i - x) - (j - y) - 1; s = abs(a[i][j] - a[x][y]) - i + x - j + y - 1; if (a[i][j] < a[x][y]) { s = a[x][y] + x + y - a[i][j] - i - j - 1; s = a[x][y] + x + y - (a[i][j] + i + j) - 1; } else { s = a[i][j] - i - j - a[x][y] + x + y - 1; s = a[i][j] - i - j - (a[x][y] - x - y) - 1; } ans = max(ans, abs(a[i][j] - a[x][y]) - abs(i - x) - abs(j - y) - 1); } } } } */ return ans; } signed main() { int n, m; cin >> n >> m; vector <vector <int>> a(n + 1, vector <int> (m + 1)); for (int i = 1; i <= n; i ++) { for (int j = 1; j <= m; j ++) cin >> a[i][j]; } int ans = sol(a); for (int i = 1; i <= n; i ++) { reverse(a[i].begin() + 1, a[i].end()); } ans = max(ans, sol(a)); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...