#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#pragma GCC optimize("Ofast")
#pragma GCC target("tune=native")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef long double ld;
#define fs first
#define sc second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define maxn 200000
#define BIG 1000000000000000000
mt19937 rnd(42);
int a[1002][1002], a1[4][1002][1002];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++)
cin >> a[i][j];
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
a1[0][i][j] = max(a[i][j], max(a1[0][i-1][j] - 1, a1[0][i][j-1] - 1));
for(int i = 1; i <= n; i++)
for(int j = m; j > 0; j--)
a1[1][i][j] = max(a[i][j], max(a1[1][i-1][j] - 1, a1[1][i][j+1] - 1));
for(int i = n; i > 0; i--)
for(int j = 1; j <= m; j++)
a1[2][i][j] = max(a[i][j], max(a1[2][i+1][j] - 1, a1[2][i][j-1] - 1));
for(int i = n; i > 0; i--)
for(int j = m; j > 0; j--)
a1[3][i][j] = max(a[i][j], max(a1[3][i+1][j] - 1, a1[3][i][j+1] - 1));
int ans = -1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
int p = a[i][j];
for(int o = 0; o < 4; o++)
ans = max(ans, a1[o][i][j] - p - 1);
}
cout << ans;
}
/*
2 3
3 4 2
5 7 5
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
4 ms |
1400 KB |
Output is correct |
10 |
Correct |
3 ms |
1400 KB |
Output is correct |
11 |
Correct |
4 ms |
1344 KB |
Output is correct |
12 |
Correct |
3 ms |
1400 KB |
Output is correct |
13 |
Correct |
4 ms |
1400 KB |
Output is correct |
14 |
Correct |
3 ms |
1400 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 |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
4 ms |
1400 KB |
Output is correct |
13 |
Correct |
3 ms |
1400 KB |
Output is correct |
14 |
Correct |
4 ms |
1344 KB |
Output is correct |
15 |
Correct |
3 ms |
1400 KB |
Output is correct |
16 |
Correct |
4 ms |
1400 KB |
Output is correct |
17 |
Correct |
3 ms |
1400 KB |
Output is correct |
18 |
Correct |
161 ms |
28348 KB |
Output is correct |
19 |
Correct |
166 ms |
21880 KB |
Output is correct |
20 |
Correct |
155 ms |
23688 KB |
Output is correct |
21 |
Correct |
162 ms |
28536 KB |
Output is correct |
22 |
Correct |
162 ms |
23544 KB |
Output is correct |
23 |
Correct |
165 ms |
24724 KB |
Output is correct |
24 |
Correct |
167 ms |
28316 KB |
Output is correct |