Submission #313366

# Submission time Handle Problem Language Result Execution time Memory
313366 2020-10-15T21:38:49 Z Temmie The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1123 ms 55028 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][m - 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;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16128 KB Output is correct
2 Correct 10 ms 16128 KB Output is correct
3 Correct 10 ms 16128 KB Output is correct
4 Correct 10 ms 16128 KB Output is correct
5 Correct 10 ms 16128 KB Output is correct
6 Correct 10 ms 16128 KB Output is correct
7 Correct 10 ms 16128 KB Output is correct
8 Correct 10 ms 16128 KB Output is correct
9 Correct 10 ms 16128 KB Output is correct
10 Correct 10 ms 16032 KB Output is correct
11 Correct 10 ms 16128 KB Output is correct
12 Correct 10 ms 16128 KB Output is correct
13 Correct 10 ms 16128 KB Output is correct
14 Correct 10 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16128 KB Output is correct
2 Correct 10 ms 16128 KB Output is correct
3 Correct 10 ms 16128 KB Output is correct
4 Correct 10 ms 16128 KB Output is correct
5 Correct 10 ms 16128 KB Output is correct
6 Correct 10 ms 16128 KB Output is correct
7 Correct 10 ms 16128 KB Output is correct
8 Correct 10 ms 16128 KB Output is correct
9 Correct 10 ms 16128 KB Output is correct
10 Correct 10 ms 16032 KB Output is correct
11 Correct 10 ms 16128 KB Output is correct
12 Correct 10 ms 16128 KB Output is correct
13 Correct 10 ms 16128 KB Output is correct
14 Correct 10 ms 16128 KB Output is correct
15 Correct 10 ms 16128 KB Output is correct
16 Correct 13 ms 16128 KB Output is correct
17 Correct 16 ms 16384 KB Output is correct
18 Correct 16 ms 16384 KB Output is correct
19 Correct 19 ms 16384 KB Output is correct
20 Correct 17 ms 16256 KB Output is correct
21 Correct 19 ms 16512 KB Output is correct
22 Correct 20 ms 16512 KB Output is correct
23 Correct 22 ms 16512 KB Output is correct
24 Correct 20 ms 16384 KB Output is correct
25 Correct 25 ms 16512 KB Output is correct
26 Correct 20 ms 16512 KB Output is correct
27 Correct 19 ms 16640 KB Output is correct
28 Correct 20 ms 16640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16128 KB Output is correct
2 Correct 10 ms 16128 KB Output is correct
3 Correct 10 ms 16128 KB Output is correct
4 Correct 10 ms 16128 KB Output is correct
5 Correct 10 ms 16128 KB Output is correct
6 Correct 10 ms 16128 KB Output is correct
7 Correct 10 ms 16128 KB Output is correct
8 Correct 10 ms 16128 KB Output is correct
9 Correct 10 ms 16128 KB Output is correct
10 Correct 10 ms 16032 KB Output is correct
11 Correct 10 ms 16128 KB Output is correct
12 Correct 10 ms 16128 KB Output is correct
13 Correct 10 ms 16128 KB Output is correct
14 Correct 10 ms 16128 KB Output is correct
15 Correct 10 ms 16128 KB Output is correct
16 Correct 13 ms 16128 KB Output is correct
17 Correct 16 ms 16384 KB Output is correct
18 Correct 16 ms 16384 KB Output is correct
19 Correct 19 ms 16384 KB Output is correct
20 Correct 17 ms 16256 KB Output is correct
21 Correct 19 ms 16512 KB Output is correct
22 Correct 20 ms 16512 KB Output is correct
23 Correct 22 ms 16512 KB Output is correct
24 Correct 20 ms 16384 KB Output is correct
25 Correct 25 ms 16512 KB Output is correct
26 Correct 20 ms 16512 KB Output is correct
27 Correct 19 ms 16640 KB Output is correct
28 Correct 20 ms 16640 KB Output is correct
29 Correct 484 ms 38264 KB Output is correct
30 Correct 533 ms 37756 KB Output is correct
31 Correct 656 ms 39416 KB Output is correct
32 Correct 477 ms 39292 KB Output is correct
33 Correct 428 ms 36344 KB Output is correct
34 Correct 584 ms 39416 KB Output is correct
35 Correct 895 ms 54952 KB Output is correct
36 Correct 808 ms 50040 KB Output is correct
37 Correct 1123 ms 55028 KB Output is correct