#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
1024 KB |
Output is correct |
11 |
Correct |
1 ms |
1024 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
928 KB |
Output is correct |
14 |
Correct |
1 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
1024 KB |
Output is correct |
15 |
Correct |
1 ms |
1024 KB |
Output is correct |
16 |
Correct |
1 ms |
928 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
164 ms |
16504 KB |
Output is correct |
19 |
Correct |
138 ms |
16248 KB |
Output is correct |
20 |
Correct |
132 ms |
16376 KB |
Output is correct |
21 |
Correct |
148 ms |
16248 KB |
Output is correct |
22 |
Correct |
139 ms |
16248 KB |
Output is correct |
23 |
Correct |
150 ms |
16248 KB |
Output is correct |
24 |
Correct |
146 ms |
15480 KB |
Output is correct |