#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int a[ 1001 ][ 1001 ];
int dp[ 2001 ][ 2001 ], dp2[ 2001 ][ 2001 ], dp3[ 2001 ][ 2001 ], dp1[ 2001 ][ 2001 ];
main () {
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i ++ )
dp[ i ][ 0 ] = dp1[ i ][ 0 ] = dp2[ i ][ 0 ] = dp3[ i ][ 0 ] = dp[ i ][ m + 1 ] = dp1[ i ][ m + 1 ] = dp2[ i ][ m + 1 ] = dp3[ i ][ m + 1 ] = oo;
for ( int i = 1; i <= m; i ++ )
dp[ 0 ][ i ] = dp1[ 0 ][ i ] = dp2[ 0 ][ i ] = dp3[ 0 ][ i ] = dp[ n + 1 ][ i ] = dp1[ n + 1 ][ i ] = dp2[ n + 1 ][ i ] = dp3[ n + 1 ][ i ] = oo;
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 ++ ) {
dp[ i ][ j ] = min( dp[ i ][ j - 1 ] + 1, min( dp[ i - 1 ][ j ] + 1, a[ i ][ j ] + 1 ) );
}
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = m; j >= 1; j -- ) {
dp1[ i ][ j ] = min( dp1[ i - 1 ][ j ] + 1, min( dp1[ i ][ j + 1 ] + 1, a[ i ][ j ] + 1 ) );
}
}
for ( int i = n; i >= 1; i -- ) {
for ( int j = 1; j <= m; j ++ ) {
dp2[ i ][ j ] = min( dp2[ i ][ j - 1 ] + 1, min( dp2[ i + 1 ][ j ] + 1, a[ i ][ j ] + 1 ) );
}
}
for ( int i = n; i >= 1; i -- ) {
for ( int j = m; j >= 1; j -- ) {
dp3[ i ][ j ] = min( dp3[ i + 1 ][ j ] + 1, min( dp3[ i ][ j + 1 ] + 1, a[ i ][ j ] + 1 ) );
}
}
ans = -oo;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
ans = max( ans, a[ i ][ j ] - min( dp[ i ][ j ], min( dp1[ i ][ j ], min( dp2[ i ][ j ], dp3[ i ][ j ] ) ) ) + 0ll );
// cout << i << " " << j << " - " << ans << "\n";
}
}
cout << ans;
}
Compilation message
maxcomp.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
2 ms |
1468 KB |
Output is correct |
10 |
Correct |
2 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1468 KB |
Output is correct |
12 |
Correct |
3 ms |
1468 KB |
Output is correct |
13 |
Correct |
2 ms |
1332 KB |
Output is correct |
14 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
1468 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
2 ms |
1468 KB |
Output is correct |
15 |
Correct |
3 ms |
1468 KB |
Output is correct |
16 |
Correct |
2 ms |
1332 KB |
Output is correct |
17 |
Correct |
1 ms |
1356 KB |
Output is correct |
18 |
Correct |
364 ms |
64104 KB |
Output is correct |
19 |
Correct |
361 ms |
64120 KB |
Output is correct |
20 |
Correct |
337 ms |
62236 KB |
Output is correct |
21 |
Correct |
361 ms |
64092 KB |
Output is correct |
22 |
Correct |
350 ms |
64076 KB |
Output is correct |
23 |
Correct |
356 ms |
64060 KB |
Output is correct |
24 |
Correct |
378 ms |
62116 KB |
Output is correct |