답안 #313362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313362 2020-10-15T21:35:54 Z Temmie The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
33 ms 32504 KB
#include <bits/stdc++.h>

std::vector <std::vector <int>> g(2001, std::vector <int> (2001, 0));
int n, m;
int mx = 0, mn = 1 << 30;
bool tr(int mid) {
	int ptr = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) if (g[i][j] + mid < mx) ptr = std::max(ptr, j + 1);
		for (int j = 0; j < m; j++) if (g[i][j] - mid > mn) if (j < ptr) return false;
	}
	return true;
}
void invc() {
	for (int i = 0; i < n; i++) for (int j = 0; j < (m >> 1); j++) std::swap(g[i][j], g[i][j - 1 - j]);
}

void invr() {
	for (int i = 0; i < (n >> 1); i++) for (int j = 0; j < m; j++) std::swap(g[i][j], g[n - 1 - i][j]);
}

int go() {
	int l = 0, r = mx - mn;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (tr(mid)) r = mid - 1;
		else l = mid + 1;
	}
	return l + 1;
}

int main() {
	std::ios::sync_with_stdio(0); std::cin.tie(0);
	std::cin >> n >> m;
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) std::cin >> g[i][j], mx = std::max(mx, g[i][j]), mn = std::min(mn, g[i][j]);
	int ans = go();
	invr(); ans = std::min(ans, go());
	invc(); ans = std::min(ans, go());
	invr(); ans = std::min(ans, go());
	std::cout << ans - 1 << std::endl;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 32504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 32504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 32504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -