Submission #814208

# Submission time Handle Problem Language Result Execution time Memory
814208 2023-08-08T06:21:37 Z GEN 이지후(#10370) Arranging Tickets (JOI17_arranging_tickets) C++17
85 / 100
381 ms 9260 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
using pi = pair<int, int>;

int n, m;
int a[MAXN], b[MAXN], c[MAXN];

bool Do(vector<int> l, vector<int> r, vector<pi> intv, int K) {
	l[0] = r[0] = 1e9;
	for (int i = 1; i < l.size(); i++)
		l[i] = min(l[i], l[i - 1]);
	for (int i = 1; i < r.size(); i++)
		r[i] = min(r[i], r[i - 1]);
	l.push_back(0);
	r.push_back(0);
	sort(intv.begin(), intv.end());
	priority_queue<int, vector<int>, greater<int>> pq;
	int ptr = 0;
	vector<int> opt(r.size());
	for (int i = 0; i + 1 < l.size(); i++) {
		while (ptr < intv.size() && intv[ptr].first <= i) {
			pq.push(intv[ptr++].second);
		}
		while (l[i + 1] < K) {
			if (pq.empty())
				return 0;
			int nxt = pq.top();
			pq.pop();
			opt[nxt]++;
			K--;
		}
	}
	for (int i = opt.size() - 2; i >= 0; i--)
		opt[i] += opt[i + 1];
	for (int i = 0; i < r.size(); i++) {
		if (opt[i] > r[i])
			return false;
	}
	return true;
}

int cnt[MAXN];
bool trial(int x) {
	int maxpos = max_element(cnt + 1, cnt + n + 1) - cnt;
	int mx = cnt[maxpos];
	if (mx <= x)
		return true;
	for (int i = mx - x; i <= mx - x + 1 && i <= m && i <= x; i++) {
		vector<int> surp(n - 1);
		bool bad = 0;
		for (int j = 0; j < n - 1; j++) {
			surp[j] = x + i - cnt[j + 1];
			if (surp[j] < 0)
				bad = true;
			surp[j] /= 2;
		}
		// number of reversal
		vector<pi> intv;
		for (int k = 0; k < m; k++) {
			if (a[k] <= maxpos && b[k] > maxpos) {
				intv.emplace_back(a[k] - 1, n - b[k]);
			}
		}
		vector<int> l = {0};
		vector<int> r = {0};
		for (int k = 0; k < maxpos - 1; k++)
			l.push_back(surp[k]);
		for (int k = n - 2; k >= maxpos; k--)
			r.push_back(surp[k]);
		if (Do(l, r, intv, i))
			return true;
	}

	return false;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		if (a[i] > b[i])
			swap(a[i], b[i]);
		cnt[a[i]]++;
		cnt[b[i]]--;
	}
	for (int i = 1; i <= n; i++)
		cnt[i] += cnt[i - 1];
	int s = 0, e = 200000;
	while (s != e) {
		int m = (s + e) / 2;
		if (trial(m))
			e = m;
		else
			s = m + 1;
	}
	cout << s << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 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 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 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 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 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 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 5 ms 468 KB Output is correct
31 Correct 4 ms 448 KB Output is correct
32 Correct 7 ms 492 KB Output is correct
33 Correct 4 ms 444 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 516 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 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 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 5 ms 468 KB Output is correct
31 Correct 4 ms 448 KB Output is correct
32 Correct 7 ms 492 KB Output is correct
33 Correct 4 ms 444 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 516 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 228 ms 8544 KB Output is correct
41 Correct 199 ms 8484 KB Output is correct
42 Correct 187 ms 9112 KB Output is correct
43 Correct 299 ms 8508 KB Output is correct
44 Correct 259 ms 8436 KB Output is correct
45 Correct 381 ms 8980 KB Output is correct
46 Correct 192 ms 8448 KB Output is correct
47 Correct 171 ms 8236 KB Output is correct
48 Correct 188 ms 8692 KB Output is correct
49 Correct 124 ms 6272 KB Output is correct
50 Correct 77 ms 5400 KB Output is correct
51 Correct 148 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 308 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 304 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 312 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 4 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 5 ms 468 KB Output is correct
31 Correct 4 ms 448 KB Output is correct
32 Correct 7 ms 492 KB Output is correct
33 Correct 4 ms 444 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 3 ms 516 KB Output is correct
36 Correct 5 ms 512 KB Output is correct
37 Correct 4 ms 512 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 228 ms 8544 KB Output is correct
41 Correct 199 ms 8484 KB Output is correct
42 Correct 187 ms 9112 KB Output is correct
43 Correct 299 ms 8508 KB Output is correct
44 Correct 259 ms 8436 KB Output is correct
45 Correct 381 ms 8980 KB Output is correct
46 Correct 192 ms 8448 KB Output is correct
47 Correct 171 ms 8236 KB Output is correct
48 Correct 188 ms 8692 KB Output is correct
49 Correct 124 ms 6272 KB Output is correct
50 Correct 77 ms 5400 KB Output is correct
51 Correct 148 ms 6272 KB Output is correct
52 Incorrect 162 ms 9260 KB Output isn't correct
53 Halted 0 ms 0 KB -