답안 #814163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
814163 2023-08-08T05:57:30 Z GEN 이지후(#10370) Arranging Tickets (JOI17_arranging_tickets) C++17
45 / 100
7 ms 508 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++) {
		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 (!bad && 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 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 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 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 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 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 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 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 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 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 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 6 ms 444 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 5 ms 448 KB Output is correct
32 Correct 7 ms 448 KB Output is correct
33 Correct 7 ms 444 KB Output is correct
34 Incorrect 6 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 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 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 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 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 6 ms 444 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 5 ms 448 KB Output is correct
32 Correct 7 ms 448 KB Output is correct
33 Correct 7 ms 444 KB Output is correct
34 Incorrect 6 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 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 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 308 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 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 340 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 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 6 ms 444 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 5 ms 448 KB Output is correct
32 Correct 7 ms 448 KB Output is correct
33 Correct 7 ms 444 KB Output is correct
34 Incorrect 6 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -