답안 #407103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407103 2021-05-18T13:22:16 Z SeDunion The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>
#ifndef LOCAL
#define cerr if(false)cerr
#endif // LOCAL
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

int a[2022][2022], b[2022][2022], n, m, mn=int(1e9+12), mx;

bool check(int k) {
	if (k * 2 < mx - mn) return 0;
	for (int i = 1 ; i <= n ; ++ i) for (int j = 1 ; j <= m ; ++ j)
		b[i][j] = (a[i][j] < mx - k ? 0 : (a[i][j] <= mn + k ? 1 : 2));
	{
		bool bad = 0;
		int l = m + 1;
		for (int i = n ; i >= 1 ; -- i) {
			for (int j = 1 ; j < l ; ++ j) {
				if (b[i][j] == 2) { l = j; break; }
			}
			for (int j = m ; j >= l ; -- j) {
				if (b[i][j] == 0) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = 0;
		for (int i = n ; i >= 1 ; -- i) {
			for (int j = m ; j > l ; -- j) {
				if (b[i][j] == 2) { l = j; break; }
			}
			for (int j = 1 ; j <= l ; ++ j) {
				if (b[i][j] == 0) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = m + 1;
		for (int i = 1 ; i <= n ; ++ i) {
			for (int j = 1 ; j < l ; ++ j) {
				if (b[i][j] == 2) { l = j; break; }
			}
			for (int j = m ; j >= l ; -- j) {
				if (b[i][j] == 0) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = 0;
		for (int i = 1 ; i <= n ; ++ i) {
			for (int j = m ; j > l ; -- j) {
				if (b[i][j] == 2) { l = j; break; }
			}
			for (int j = 1 ; j <= l ; ++ j) {
				if (b[i][j] == 0) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = m + 1;
		for (int i = n ; i >= 1 ; -- i) {
			for (int j = 1 ; j < l ; ++ j) {
				if (b[i][j] == 0) { l = j; break; }
			}
			for (int j = m ; j >= l ; -- j) {
				if (b[i][j] == 2) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = 0;
		for (int i = n ; i >= 1 ; -- i) {
			for (int j = m ; j > l ; -- j) {
				if (b[i][j] == 0) { l = j; break; }
			}
			for (int j = 1 ; j <= l ; ++ j) {
				if (b[i][j] == 2) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = m + 1;
		for (int i = 1 ; i <= n ; ++ i) {
			for (int j = 1 ; j < l ; ++ j) {
				if (b[i][j] == 0) { l = j; break; }
			}
			for (int j = m ; j >= l ; -- j) {
				if (b[i][j] == 2) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	{
		bool bad = 0;
		int l = 0;
		for (int i = 1 ; i <= n ; ++ i) {
			for (int j = m ; j > l ; -- j) {
				if (b[i][j] == 0) { l = j; break; }
			}
			for (int j = 1 ; j <= l ; ++ j) {
				if (b[i][j] == 2) bad = 1;
			}
		}
		if (!bad) return 1;
	}
	return 0;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1 ; i <= n ; ++ i) for (int j = 1 ; j <= m ; ++ j)
		cin >> a[i][j], mn = min(mn, a[i][j]), mx = max(mx, a[i][j]);
	int l = 0, r = int(1e9 + 12);
	while (l < r) {
		int m = (l + r) / 2;
		if (check(m)) r = m;
		else l = m + 1;
	}
	cout << r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -