Submission #44828

#TimeUsernameProblemLanguageResultExecution timeMemory
44828aomeMaxcomp (info1cup18_maxcomp)C++17
100 / 100
231 ms24428 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1005; const long long INF = 1e18; int n, m; long long a[N][N]; long long f1[N][N], f2[N][N]; long long res; void reset() { for (int i = 0; i <= n + 1; ++i) { for (int j = 0; j <= m + 1; ++j) { f1[i][j] = f2[i][j] = -INF; } } } int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; } } res = -INF; reset(); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { f1[i][j] = max(max(f1[i - 1][j], f1[i][j - 1]), -a[i][j] + i + j); f2[i][j] = max(max(f2[i - 1][j], f2[i][j - 1]), +a[i][j] + i + j); res = max(res, f1[i][j] + a[i][j] - i - j); res = max(res, f2[i][j] - a[i][j] - i - j); } } reset(); for (int i = 1; i <= n; ++i) { for (int j = m; j >= 1; --j) { f1[i][j] = max(max(f1[i - 1][j], f1[i][j + 1]), -a[i][j] + i - j); f2[i][j] = max(max(f2[i - 1][j], f2[i][j + 1]), +a[i][j] + i - j); res = max(res, f1[i][j] + a[i][j] - i + j); res = max(res, f2[i][j] - a[i][j] - i + j); } } reset(); for (int i = n; i >= 1; --i) { for (int j = 1; j <= m; ++j) { f1[i][j] = max(max(f1[i + 1][j], f1[i][j - 1]), -a[i][j] - i + j); f2[i][j] = max(max(f2[i + 1][j], f2[i][j - 1]), +a[i][j] - i + j); res = max(res, f1[i][j] + a[i][j] + i - j); res = max(res, f2[i][j] - a[i][j] + i - j); } } reset(); for (int i = n; i >= 1; --i) { for (int j = m; j >= 1; --j) { f1[i][j] = max(max(f1[i + 1][j], f1[i][j + 1]), -a[i][j] - i - j); f2[i][j] = max(max(f2[i + 1][j], f2[i][j + 1]), +a[i][j] - i - j); res = max(res, f1[i][j] + a[i][j] + i + j); res = max(res, f2[i][j] - a[i][j] + i + j); } } cout << res - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...