//#include "/Users/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair < int, int >
#define fs first
#define sc second
#define getfiles ifstream cin("input.txt"); ofstream cout("output.txt");
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef long long ll;
typedef long double ld;
const int INF = 2e9;
const ll BIG_INF = 1e18;
const ll MOD = 1e9 + 7;
const int maxn = 1e3 + 5;
int mat[maxn][maxn], pref[maxn][maxn];
int a[maxn][maxn], n, m, ans;
void rev(int i_k, int j_k) {
if (i_k == -1 && j_k == -1)
return;
if (!(i_k == -1 && j_k == 1)) {
for (int i = 0; i < n / 2; i++)
for (int j = 0; j < m; j++)
swap(mat[i][j], mat[n - i - 1][j]);
}
if (i_k == 1 && j_k == -1)
return;
for (int i = 0; i < n; i++)
for (int j = 0; j < m / 2; j++)
swap(mat[i][j], mat[i][m - j - 1]);
}
void upd(int i_k, int j_k) {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
mat[i][j] = a[i][j] + i_k * i + j_k * j;
rev(i_k, j_k);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
pref[i + 1][j + 1] = min(min(pref[i + 1][j], pref[i][j + 1]), mat[i][j]);
}
void upd_ans() {
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans = max(ans, mat[i][j] - pref[i + 1][j + 1] - 1);
}
int main() {
fast_io
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++)
pref[i][j] = INF;
ans = -1;
upd(1, 1);
upd_ans();
upd(1, -1);
upd_ans();
upd(-1, 1);
upd_ans();
upd(-1, -1);
upd_ans();
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
3 ms |
888 KB |
Output is correct |
12 |
Correct |
3 ms |
888 KB |
Output is correct |
13 |
Correct |
3 ms |
1016 KB |
Output is correct |
14 |
Correct |
3 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
1016 KB |
Output is correct |
13 |
Correct |
3 ms |
1016 KB |
Output is correct |
14 |
Correct |
3 ms |
888 KB |
Output is correct |
15 |
Correct |
3 ms |
888 KB |
Output is correct |
16 |
Correct |
3 ms |
1016 KB |
Output is correct |
17 |
Correct |
3 ms |
888 KB |
Output is correct |
18 |
Correct |
160 ms |
13560 KB |
Output is correct |
19 |
Correct |
160 ms |
15224 KB |
Output is correct |
20 |
Correct |
152 ms |
20376 KB |
Output is correct |
21 |
Correct |
160 ms |
13580 KB |
Output is correct |
22 |
Correct |
161 ms |
20708 KB |
Output is correct |
23 |
Correct |
161 ms |
20680 KB |
Output is correct |
24 |
Correct |
155 ms |
12972 KB |
Output is correct |