답안 #135932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
135932 2019-07-24T13:48:56 Z gs14004 Arranging Tickets (JOI17_arranging_tickets) C++17
45 / 100
12 ms 600 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
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);
		for(int j=0; j<n-1; j++){
			surp[j] = x + i - cnt[j + 1];
			surp[j] /= 2;
		}
		// number of reversal
		int j = maxpos;
		assert(j - 1 < surp.size() && surp[j - 1] == 0);
		vector<pi> intv;
		for(int k=0; k<m; k++){
			if(a[k] <= j && b[k] > j){
				intv.emplace_back(a[k] - 1, n - b[k]);
			}
		}
		vector<int> l = {0};
		vector<int> r = {0};
		for(int k=0; k<j-1; k++) l.push_back(surp[k]);
		for(int k=n-2; k>=j; 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 = 10000;
	while(s != e){
		int m = (s+e)/2;
		if(trial(m)) e = m;
		else s = m+1;
	}
	cout << s << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 2 ms 252 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 2 ms 252 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 10 ms 504 KB Output is correct
29 Correct 10 ms 508 KB Output is correct
30 Correct 11 ms 504 KB Output is correct
31 Correct 11 ms 504 KB Output is correct
32 Correct 12 ms 600 KB Output is correct
33 Correct 12 ms 480 KB Output is correct
34 Incorrect 10 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 2 ms 252 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 10 ms 504 KB Output is correct
29 Correct 10 ms 508 KB Output is correct
30 Correct 11 ms 504 KB Output is correct
31 Correct 11 ms 504 KB Output is correct
32 Correct 12 ms 600 KB Output is correct
33 Correct 12 ms 480 KB Output is correct
34 Incorrect 10 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 372 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 2 ms 252 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 10 ms 504 KB Output is correct
29 Correct 10 ms 508 KB Output is correct
30 Correct 11 ms 504 KB Output is correct
31 Correct 11 ms 504 KB Output is correct
32 Correct 12 ms 600 KB Output is correct
33 Correct 12 ms 480 KB Output is correct
34 Incorrect 10 ms 508 KB Output isn't correct
35 Halted 0 ms 0 KB -