이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |