Submission #586902

# Submission time Handle Problem Language Result Execution time Memory
586902 2022-07-01T01:23:15 Z dutinmeow The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1361 ms 54984 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int N, M;
	cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(M));
	int vmn = INT_MAX, vmx = INT_MIN;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
			vmn = min(vmn, A[i][j]);
			vmx = max(vmx, A[i][j]);
		}
	}

	int ans = INT_MAX;
	for (int i = 0; i < 4; i++) {
		int bl = 0, br = vmx - vmn;
		while (bl < br) {
			int bm = (bl + br) / 2;

			int bnd = 0, wrk = 1;
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < M; j++)
					if (A[i][j] < vmx - bm)
						bnd = max(bnd, j + 1);
				for (int j = 0; j < M; j++) {
					if (vmn + bm < A[i][j]) {
						if (j < bnd) {
							wrk = 0;
							break;
						}
					}
				}
			}

			if (wrk)
				br = bm;
			else 
				bl = bm + 1;
		}

		ans = min(ans, bl);
		
		if (i == 0 || i == 2) {
			for (int i = 0; i < N / 2; i++)
				for (int j = 0; j < M; j++)
					swap(A[i][j], A[N - 1 - i][j]);
		} 
		if (i == 1) {
			for (int i = 0; i < N; i++)
				for (int j = 0; j < M / 2; j++)
					swap(A[i][j], A[i][M - 1 - j]);
		}
	}

	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 9 ms 724 KB Output is correct
18 Correct 8 ms 724 KB Output is correct
19 Correct 10 ms 720 KB Output is correct
20 Correct 10 ms 596 KB Output is correct
21 Correct 12 ms 852 KB Output is correct
22 Correct 12 ms 844 KB Output is correct
23 Correct 13 ms 852 KB Output is correct
24 Correct 15 ms 712 KB Output is correct
25 Correct 16 ms 848 KB Output is correct
26 Correct 12 ms 852 KB Output is correct
27 Correct 12 ms 852 KB Output is correct
28 Correct 12 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 9 ms 724 KB Output is correct
18 Correct 8 ms 724 KB Output is correct
19 Correct 10 ms 720 KB Output is correct
20 Correct 10 ms 596 KB Output is correct
21 Correct 12 ms 852 KB Output is correct
22 Correct 12 ms 844 KB Output is correct
23 Correct 13 ms 852 KB Output is correct
24 Correct 15 ms 712 KB Output is correct
25 Correct 16 ms 848 KB Output is correct
26 Correct 12 ms 852 KB Output is correct
27 Correct 12 ms 852 KB Output is correct
28 Correct 12 ms 840 KB Output is correct
29 Correct 689 ms 37292 KB Output is correct
30 Correct 721 ms 36408 KB Output is correct
31 Correct 874 ms 39176 KB Output is correct
32 Correct 705 ms 39148 KB Output is correct
33 Correct 565 ms 34128 KB Output is correct
34 Correct 808 ms 39332 KB Output is correct
35 Correct 1099 ms 54896 KB Output is correct
36 Correct 928 ms 47884 KB Output is correct
37 Correct 1361 ms 54984 KB Output is correct