Submission #896421

# Submission time Handle Problem Language Result Execution time Memory
896421 2024-01-01T12:21:03 Z goodspeed0208 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1212 ms 70940 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<utility>
#define int long long
#define INF 1000000000000000000
using namespace std;

int n, m;
int minn = INF, maxx = -INF;
vector<vector<int> >v;

bool check(int t) {
	int smallmax = minn + t, bigmin = maxx - t;
	// small 在下
	vector<int>smalllimit(m, 0), biglimit(m, n);
	for (int j = 0 ; j < m ; j++) {
		for (int i = n-1 ; i >= 0 ; i--) {
			if (v[i][j] > smallmax) {
				smalllimit[j] = i+1;
				break;
			}
		}
		for (int i = 0 ; i < n ; i++) {
			if (v[i][j] < bigmin) {
				biglimit[j] = i-1;
				break;
			}
		} 
	} 
	// 左 到右 下到上 
	bool can = 1;
	int last = n+1;
	for (int i = 0 ; i < m ; i++) {
		last = min(last, biglimit[i]);
		if (last + 1 < smalllimit[i]) {
			can = 0;
			break;
		}
	}
	if (can) return 1;
	can = 1;
	last = n+1;
	for (int i = m-1 ; i >= 0 ; i--) {
		last = min(last, biglimit[i]);
		if (last + 1 < smalllimit[i]) {
			can = 0;
			break;
		}
	}
	return can;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	v = vector<vector<int> >(n, vector<int>(m));
	for (int i = 0 ; i < n ; i++) {
		for (int j = 0 ; j < m ; j++) {
			cin >> v[i][j];
			if (v[i][j] < minn) minn = v[i][j];
			if (v[i][j] > maxx) maxx = v[i][j];
		}
	}
	int ans = INF;
	int l = 0, r = 1000000005, mid;
	while (l + 1 < r) {
		mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	ans = min(ans, r);
	for (int j = 0 ; j < m ; j++) {
		for (int i = 0 ; i < n/2 ; i++) {
			swap(v[i][j], v[n-i-1][j]); 
		}
	}
	l = 0, r = 1000000005, mid;
	while (l + 1 < r) {
		mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	ans = min(ans, r);
	cout << ans << "\n";
}











Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:82:28: warning: right operand of comma operator has no effect [-Wunused-value]
   82 |  l = 0, r = 1000000005, mid;
      |                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 6 ms 860 KB Output is correct
18 Correct 5 ms 1048 KB Output is correct
19 Correct 6 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 6 ms 1116 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 6 ms 860 KB Output is correct
25 Correct 5 ms 1116 KB Output is correct
26 Correct 5 ms 1116 KB Output is correct
27 Correct 5 ms 1116 KB Output is correct
28 Correct 6 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 6 ms 860 KB Output is correct
18 Correct 5 ms 1048 KB Output is correct
19 Correct 6 ms 860 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 6 ms 1116 KB Output is correct
22 Correct 5 ms 1116 KB Output is correct
23 Correct 5 ms 1116 KB Output is correct
24 Correct 6 ms 860 KB Output is correct
25 Correct 5 ms 1116 KB Output is correct
26 Correct 5 ms 1116 KB Output is correct
27 Correct 5 ms 1116 KB Output is correct
28 Correct 6 ms 1148 KB Output is correct
29 Correct 1069 ms 52816 KB Output is correct
30 Correct 1096 ms 51332 KB Output is correct
31 Correct 989 ms 54944 KB Output is correct
32 Correct 1212 ms 54868 KB Output is correct
33 Correct 1088 ms 48052 KB Output is correct
34 Correct 1202 ms 55140 KB Output is correct
35 Correct 1091 ms 70708 KB Output is correct
36 Correct 849 ms 61776 KB Output is correct
37 Correct 1046 ms 70940 KB Output is correct