#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 ) );
}
}
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 () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |