제출 #317083

#제출 시각아이디문제언어결과실행 시간메모리
317083Kevin_Zhang_TWMaxcomp (info1cup18_maxcomp)C++17
100 / 100
164 ms16504 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define AI(i) begin(i), end(i) #define pb emplace_back #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] : ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 1010, inf = 1e9; int n, m; ll a[MAX_N][MAX_N], pf[MAX_N][MAX_N]; ll cal() { for (int i = 0;i <= n;++i) for (int j = 0;j <= m;++j) pf[i][j] = -inf; ll res = -inf; for (int i = 1;i <= n;++i) { for (int j = 1;j <= m;++j) { pf[i][j] = max(pf[i-1][j], pf[i][j-1]); res = max(res, a[i][j] - i - j - 1 + pf[i][j]); pf[i][j] = max(pf[i][j], i + j - a[i][j]); } } return res; } ll solve() { ll res = -inf; res = max(res, cal()); for (int i = 1;i <= n;++i) reverse(a[i]+1, a[i]+1+m); res = max(res, cal()); for (int l = 1, r = n;l < r;++l, --r) swap(a[l], a[r]); res = max(res, cal()); for (int i = 1;i <= n;++i) reverse(a[i]+1, a[i]+1+m); res = max(res, cal()); return res; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (int i = 1;i <= n;++i) for (int j = 1;j <= m;++j) cin >> a[i][j]; cout << solve() << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...