답안 #716000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716000 2023-03-28T18:22:18 Z vinnipuh01 The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1191 ms 78800 KB
#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 sqrt sqrtl

using namespace std;

const long long oo = 2e9;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;


    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 () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	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 ] + 0ll );
		}
	}
	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;
}

Compilation message

joioi.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  109 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 6 ms 4948 KB Output is correct
17 Correct 9 ms 5044 KB Output is correct
18 Correct 8 ms 5076 KB Output is correct
19 Correct 10 ms 5076 KB Output is correct
20 Correct 10 ms 4820 KB Output is correct
21 Correct 12 ms 5132 KB Output is correct
22 Correct 12 ms 5076 KB Output is correct
23 Correct 11 ms 5076 KB Output is correct
24 Correct 9 ms 4868 KB Output is correct
25 Correct 11 ms 5076 KB Output is correct
26 Correct 15 ms 5076 KB Output is correct
27 Correct 12 ms 5132 KB Output is correct
28 Correct 13 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 6 ms 4948 KB Output is correct
17 Correct 9 ms 5044 KB Output is correct
18 Correct 8 ms 5076 KB Output is correct
19 Correct 10 ms 5076 KB Output is correct
20 Correct 10 ms 4820 KB Output is correct
21 Correct 12 ms 5132 KB Output is correct
22 Correct 12 ms 5076 KB Output is correct
23 Correct 11 ms 5076 KB Output is correct
24 Correct 9 ms 4868 KB Output is correct
25 Correct 11 ms 5076 KB Output is correct
26 Correct 15 ms 5076 KB Output is correct
27 Correct 12 ms 5132 KB Output is correct
28 Correct 13 ms 5076 KB Output is correct
29 Correct 755 ms 77084 KB Output is correct
30 Correct 919 ms 76480 KB Output is correct
31 Correct 1008 ms 78664 KB Output is correct
32 Correct 846 ms 78720 KB Output is correct
33 Correct 670 ms 74832 KB Output is correct
34 Correct 851 ms 78640 KB Output is correct
35 Correct 1191 ms 78516 KB Output is correct
36 Correct 915 ms 74448 KB Output is correct
37 Correct 1122 ms 78800 KB Output is correct