이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
#define sqrt sqrtl
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[ 4 ][ 2001 ][ 2001 ], n, m;
int b[ 2001 ][ 2001 ];
bool ok( int x ) {
for ( int t = 0; t < 4; t ++ ) {
if ( t & 1 ) {
mx = n;
for ( int i = 1; i <= m; i ++ ) {
for ( int j = 1; j <= n; j ++ )
b[ i ][ j ] = 0;
}
for ( int i = 1; i <= m; i ++ ) {
for ( int j = 1; j <= mx; j ++ ) {
if ( a[ t ][ i ][ j ] > x ) {
mx = j - 1;
break;
}
b[ i ][ j ] = 1;
}
}
int mnn = oo;
int mxx = 0;
for ( int i = 1; i <= m; i ++ ) {
for ( int j = 1; j <= n; j ++ ) {
if ( !b[ i ][ j ] ) {
mxx = max( mxx, a[ t ][ i ][ j ] ) ;
mnn = min( mnn, a[ t ][ i ][ j ] );
}
}
}
if ( mxx - mnn <= x )
return true;
}
else {
mx = m;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ )
b[ i ][ j ] = 0;
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= mx; j ++ ) {
if ( a[ t ][ i ][ j ] > x ) {
mx = j - 1;
break;
}
b[ i ][ j ] = 1;
}
}
int mnn = oo;
int mxx = 0;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
if ( !b[ i ][ j ] ) {
mxx = max( mxx, a[ t ][ i ][ j ] ) ;
mnn = min( mnn, a[ t ][ i ][ j ] );
}
}
}
if ( mxx - mnn <= x )
return true;
}
}
return false;
}
main () {
cin >> n >> m;
mn = oo;
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ ) {
cin >> a[ 0 ][ i ][ j ];
mn = min( mn, a[ 0 ][ i ][ j ] );
}
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 1; j <= m; j ++ )
a[ 0 ][ i ][ j ] -= mn;
}
int x, y;
x = y = 1;
for ( int j = m; j >= 1; j -- ) {
y = 1;
for ( int i = 1; i <= n; i ++ ) {
a[ 1 ][ x ][ y ] = a[ 0 ][ i ][ j ];
y ++;
}
x ++;
}
x = 1;
for ( int i = n; i >= 1; i -- ) {
y = 1;
for ( int j = m; j >= 1; j -- )
a[ 2 ][ x ][ y ] = a[ 0 ][ i ][ j ], y ++;
x ++;
}
x = 1;
for ( int j = 1; j <= m; j ++ ) {
y = 1;
for ( int i = n; i >= 1; i -- )
a[ 3 ][ x ][ y ] = a[ 0 ][ i ][ j ], y ++;
x ++;
}
// for ( int t = 0; t < 4; t ++ ) {
// cout << "----------\n";
// for ( int i = 1; i <= n; i ++ ) {
// for ( int j = 1; j <= m; j ++ )
// cout << a[ t ][ i ][ j ] << " ";
// cout << "\n";
// }
// cout << "----------\n";
// }
int l, r, mid;
l = 0;
r = 1e9;
while ( r > l ) {
mid = ( l + r ) / 2;
if ( ok( mid ) )
r = mid;
else
l = mid + 1;
}
cout << l;
}
컴파일 시 표준 에러 (stderr) 메시지
joioi.cpp:112:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
112 | main () {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |