#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 )
*/
set<int> dp[ 1001 ][ 1001 ][ 2 ];
int a[ 1001 ][ 1001 ];
int f( int i, int j ) {
return ( *dp[ i ][ j ][ 1 ].rbegin() - *dp[ i ][ j ][ 1 ].begin() - dp[ i ][ j ][ 1 ].size() );
}
main () {
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
cin >> a[ i ][ j ];
}
}
dp[ 1 ][ 1 ][ 1 ].insert( a[ 1 ][ 1 ] );
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
dp[ i ][ j ][ 1 ].insert( a[ i ][ j ] );
if ( j > 1 ) {
dp[ i ][ j - 1 ][ 1 ].insert( a[ i ][ j ] );
if ( f( i, j - 1 ) > f( i, j ) ) {
dp[ i ][ j ][ 1 ] = dp[ i ][ j - 1 ][ 1 ];
}
dp[ i ][ j - 1 ][ 1 ].erase( a[ i ][ j ] );
}
if ( i > 1 ) {
dp[ i - 1 ][ j ][ 1 ].insert( a[ i ][ j ] );
if ( f( i - 1, j ) > f( i, j ) )
dp[ i ][ j ][ 1 ].swap( dp[ i - 1 ][ j ][ 1 ] );
}
mx = max( mx, f( i, j ) + 0ll );
}
}
cout << mx << "\n";
}
/*
4
3 3 4
4 ^ 6 ^ 8 ^ 5 ^ 6 ^ 7 = 14
2 3
2 4 3
5 7 5
*/
Compilation message
maxcomp.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
94384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
117752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
94384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
94384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |