#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
const int N = 1 << 10;
const int INF = 1e18;
int n;
int m;
int a[N][N];
void rot() {
for (int i = 0; i < N; ++i) {
for (int j = i; j < N; ++j) {
swap(a[i][j], a[j][i]);
}
}
swap(n, m);
for (int i = 0; i < n; ++i) {
reverse(a[i], a[i] + m);
}
}
int answer = -1;
int dp[N][N];
void solve() {
fill_n(dp[0], N * N, INF);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i][j] = a[i][j] - i - j;
if (i) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
}
if (j) {
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
answer = max(answer, a[i][j] - i - j - 1 - dp[i][j]);
}
}
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
for (int it = 0; it < 4; ++it) {
if (it) {
rot();
}
solve();
}
cout << answer << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
16748 KB |
Output is correct |
2 |
Correct |
34 ms |
16748 KB |
Output is correct |
3 |
Correct |
34 ms |
16748 KB |
Output is correct |
4 |
Correct |
37 ms |
16768 KB |
Output is correct |
5 |
Correct |
35 ms |
16748 KB |
Output is correct |
6 |
Correct |
34 ms |
16748 KB |
Output is correct |
7 |
Correct |
34 ms |
16748 KB |
Output is correct |
8 |
Correct |
34 ms |
16748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
16876 KB |
Output is correct |
2 |
Correct |
37 ms |
16748 KB |
Output is correct |
3 |
Correct |
34 ms |
16748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
16748 KB |
Output is correct |
2 |
Correct |
34 ms |
16748 KB |
Output is correct |
3 |
Correct |
34 ms |
16748 KB |
Output is correct |
4 |
Correct |
37 ms |
16768 KB |
Output is correct |
5 |
Correct |
35 ms |
16748 KB |
Output is correct |
6 |
Correct |
34 ms |
16748 KB |
Output is correct |
7 |
Correct |
34 ms |
16748 KB |
Output is correct |
8 |
Correct |
34 ms |
16748 KB |
Output is correct |
9 |
Correct |
34 ms |
16876 KB |
Output is correct |
10 |
Correct |
35 ms |
16876 KB |
Output is correct |
11 |
Correct |
35 ms |
16748 KB |
Output is correct |
12 |
Correct |
35 ms |
16748 KB |
Output is correct |
13 |
Correct |
34 ms |
16748 KB |
Output is correct |
14 |
Correct |
35 ms |
16748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
16748 KB |
Output is correct |
2 |
Correct |
34 ms |
16748 KB |
Output is correct |
3 |
Correct |
34 ms |
16748 KB |
Output is correct |
4 |
Correct |
37 ms |
16768 KB |
Output is correct |
5 |
Correct |
35 ms |
16748 KB |
Output is correct |
6 |
Correct |
34 ms |
16748 KB |
Output is correct |
7 |
Correct |
34 ms |
16748 KB |
Output is correct |
8 |
Correct |
34 ms |
16748 KB |
Output is correct |
9 |
Correct |
34 ms |
16876 KB |
Output is correct |
10 |
Correct |
37 ms |
16748 KB |
Output is correct |
11 |
Correct |
34 ms |
16748 KB |
Output is correct |
12 |
Correct |
34 ms |
16876 KB |
Output is correct |
13 |
Correct |
35 ms |
16876 KB |
Output is correct |
14 |
Correct |
35 ms |
16748 KB |
Output is correct |
15 |
Correct |
35 ms |
16748 KB |
Output is correct |
16 |
Correct |
34 ms |
16748 KB |
Output is correct |
17 |
Correct |
35 ms |
16748 KB |
Output is correct |
18 |
Correct |
187 ms |
16748 KB |
Output is correct |
19 |
Correct |
183 ms |
25452 KB |
Output is correct |
20 |
Correct |
179 ms |
24940 KB |
Output is correct |
21 |
Correct |
185 ms |
25340 KB |
Output is correct |
22 |
Correct |
180 ms |
25324 KB |
Output is correct |
23 |
Correct |
184 ms |
25324 KB |
Output is correct |
24 |
Correct |
192 ms |
26092 KB |
Output is correct |