답안 #223591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223591 2020-04-15T14:24:02 Z DodgeBallMan The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1322 ms 39288 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 2e3 + 10;
int H, W, A[N][N];
int gmin, gmax;
 
bool check( int th )
{
	int sep = 0;
	for( int i = 0 ; i < H ; ++i ) {
		for( int j = 0 ; j < W ; ++j ) {
			if( A[i][j] < gmax - th ) {
				sep = max( sep, j + 1 );
			}
		}
		for( int j = 0; j < W; ++j ) {
			if( gmin + th < A[i][j] ) {
				if (j < sep) return false;
			}
		}
	}
	return true;
}
void flip_row()
{
	for (int i = 0; i < H / 2; ++i) {
		for (int j = 0; j < W; ++j) {
			swap(A[i][j], A[H - 1 - i][j]);
		}
	}
}
void flip_col()
{
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W / 2; ++j) {
			swap(A[i][j], A[i][W - 1 - j]);
		}
	}
}
int solve()
{
	int lo = 0, hi = gmax - gmin;
	while (lo < hi) {
		int mid = (lo + hi) / 2;
		if (check(mid)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	return lo;
}
int main()
{
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			scanf("%d", &(A[i][j]));
		}
	}
 
	gmin = gmax = A[0][0];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			gmin = min(gmin, A[i][j]);
			gmax = max(gmax, A[i][j]);
		}
	}
 
	int ret = solve();
	flip_row();
	ret = min(ret, solve());
	flip_col();
	ret = min(ret, solve());
	flip_row();
	ret = min(ret, solve());
	printf("%d\n", ret);
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &H, &W);
  ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &(A[i][j]));
    ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 9 ms 1280 KB Output is correct
17 Correct 13 ms 1536 KB Output is correct
18 Correct 13 ms 1536 KB Output is correct
19 Correct 14 ms 1536 KB Output is correct
20 Correct 13 ms 1440 KB Output is correct
21 Correct 16 ms 1664 KB Output is correct
22 Correct 17 ms 1664 KB Output is correct
23 Correct 18 ms 1664 KB Output is correct
24 Correct 16 ms 1536 KB Output is correct
25 Correct 22 ms 1664 KB Output is correct
26 Correct 18 ms 1664 KB Output is correct
27 Correct 17 ms 1664 KB Output is correct
28 Correct 16 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 9 ms 1280 KB Output is correct
17 Correct 13 ms 1536 KB Output is correct
18 Correct 13 ms 1536 KB Output is correct
19 Correct 14 ms 1536 KB Output is correct
20 Correct 13 ms 1440 KB Output is correct
21 Correct 16 ms 1664 KB Output is correct
22 Correct 17 ms 1664 KB Output is correct
23 Correct 18 ms 1664 KB Output is correct
24 Correct 16 ms 1536 KB Output is correct
25 Correct 22 ms 1664 KB Output is correct
26 Correct 18 ms 1664 KB Output is correct
27 Correct 17 ms 1664 KB Output is correct
28 Correct 16 ms 1664 KB Output is correct
29 Correct 642 ms 37388 KB Output is correct
30 Correct 668 ms 37624 KB Output is correct
31 Correct 833 ms 39160 KB Output is correct
32 Correct 640 ms 39288 KB Output is correct
33 Correct 546 ms 34168 KB Output is correct
34 Correct 754 ms 39288 KB Output is correct
35 Correct 1084 ms 28664 KB Output is correct
36 Correct 980 ms 25720 KB Output is correct
37 Correct 1322 ms 28540 KB Output is correct