답안 #103749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103749 2019-04-02T12:16:50 Z RockyB The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
2 ms 384 KB
#include <cstdio>
#include <algorithm>
using namespace std;
 
int H, W, A[2020][2020];
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 i = 0; i < H; ++i) {
		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:58: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:61: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 2 ms 256 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -