답안 #548858

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548858 2022-04-14T15:16:12 Z lorenzoferrari Political Development (BOI17_politicaldevelopment) C++17
100 / 100
2903 ms 11852 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
using namespace std;

clock_t tbegin;
constexpr float TL = 2.9;
int n, k, best = 0;
vector<int> o, ro;
vector<vector<int>> adj;

inline vector<int> intersect(const vector<int>& a, const vector<int>& b) {
	vector<int> ans;
	for (int i = 0, j = 0; i < int(a.size()) && j < int(b.size());) {
		if (a[i] == b[j]) {
			ans.push_back(a[i]);
			++i, ++j;
		} else if (ro[a[i]] < ro[b[j]]) {
			++i;
		} else {
			++j;
		}
	}
	return ans;
}

vector<vector<int>> cur;

void solve(int step, int i = 0) {
	best = max(best, step);
	if (int(cur.back().size()) <= i ||
		step + int(cur.back().size()) <= best ||
		best == k ||
		clock() - tbegin > TL*CLOCKS_PER_SEC) return;
	cur.push_back(intersect(cur.back(), adj[cur.back()[i]]));
	solve(step+1);
	cur.pop_back();
	solve(step, i+1);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	tbegin = clock();
	cin >> n >> k;
	o.resize(n);
	ro.resize(n);
	adj.resize(n);
	for (int i = 0; i < n; ++i) {
		int d; cin >> d;
		for (int a; d--;) {
			cin >> a;
			adj[i].push_back(a);
		}
	}
	iota(o.begin(), o.end(), 0);
	sort(o.begin(), o.end(), [&](int i, int j){
		return adj[i].size() > adj[j].size();
	});
	cur.push_back(o);
	for (int i = 0; i < n; ++i) ro[o[i]] = i;
	vector<vector<int>> aa(n);
	for (int i = 0; i < n; ++i) {
		for (int j : adj[i]) {
			if (ro[i] < ro[j]) {
				aa[i].push_back(j);
			}
		}
	}
	adj = aa;
	for (auto& x : adj) {
		sort(x.begin(), x.end(), [&](int i, int j){return ro[i]<ro[j];});
	}
	solve(0);
	cout << best << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 908 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 908 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 6 ms 848 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 6 ms 852 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 4 ms 596 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 3 ms 584 KB Output is correct
25 Correct 4 ms 856 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 25 ms 852 KB Output is correct
28 Correct 19 ms 916 KB Output is correct
29 Correct 25 ms 852 KB Output is correct
30 Correct 18 ms 964 KB Output is correct
31 Correct 26 ms 852 KB Output is correct
32 Correct 19 ms 848 KB Output is correct
33 Correct 28 ms 852 KB Output is correct
34 Correct 26 ms 852 KB Output is correct
35 Correct 8 ms 596 KB Output is correct
36 Correct 10 ms 636 KB Output is correct
37 Correct 9 ms 588 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 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 324 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 336 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2903 ms 11768 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 2902 ms 11772 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 2902 ms 11768 KB Output is correct
16 Correct 2903 ms 11672 KB Output is correct
17 Correct 2902 ms 11776 KB Output is correct
18 Correct 2903 ms 11852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 908 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 6 ms 848 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 6 ms 852 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 4 ms 596 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 3 ms 584 KB Output is correct
25 Correct 4 ms 856 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 25 ms 852 KB Output is correct
28 Correct 19 ms 916 KB Output is correct
29 Correct 25 ms 852 KB Output is correct
30 Correct 18 ms 964 KB Output is correct
31 Correct 26 ms 852 KB Output is correct
32 Correct 19 ms 848 KB Output is correct
33 Correct 28 ms 852 KB Output is correct
34 Correct 26 ms 852 KB Output is correct
35 Correct 8 ms 596 KB Output is correct
36 Correct 10 ms 636 KB Output is correct
37 Correct 9 ms 588 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 7 ms 1188 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 4 ms 920 KB Output is correct
47 Correct 38 ms 1220 KB Output is correct
48 Correct 28 ms 1008 KB Output is correct
49 Correct 38 ms 1236 KB Output is correct
50 Correct 40 ms 1256 KB Output is correct
51 Correct 11 ms 1796 KB Output is correct
52 Correct 3 ms 852 KB Output is correct
53 Correct 31 ms 1876 KB Output is correct
54 Correct 13 ms 1872 KB Output is correct
55 Correct 7 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct
57 Correct 3 ms 584 KB Output is correct
58 Correct 37 ms 1904 KB Output is correct
59 Correct 4 ms 980 KB Output is correct
60 Correct 7 ms 852 KB Output is correct
61 Correct 4 ms 980 KB Output is correct
62 Correct 32 ms 976 KB Output is correct
63 Correct 9 ms 1108 KB Output is correct
64 Correct 40 ms 1108 KB Output is correct
65 Correct 4 ms 984 KB Output is correct
66 Correct 31 ms 988 KB Output is correct
67 Correct 8 ms 1368 KB Output is correct
68 Correct 41 ms 1180 KB Output is correct
69 Correct 4 ms 976 KB Output is correct
70 Correct 38 ms 1112 KB Output is correct
71 Correct 9 ms 1364 KB Output is correct
72 Correct 43 ms 1240 KB Output is correct
73 Correct 31 ms 928 KB Output is correct
74 Correct 36 ms 1112 KB Output is correct
75 Correct 38 ms 1248 KB Output is correct
76 Correct 25 ms 1072 KB Output is correct
77 Correct 55 ms 1512 KB Output is correct
78 Correct 25 ms 920 KB Output is correct
79 Correct 25 ms 912 KB Output is correct
80 Correct 25 ms 980 KB Output is correct
81 Correct 58 ms 1504 KB Output is correct
82 Correct 3 ms 468 KB Output is correct
83 Correct 21 ms 852 KB Output is correct
84 Correct 47 ms 1412 KB Output is correct
85 Correct 3 ms 468 KB Output is correct
86 Correct 49 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 908 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 3 ms 832 KB Output is correct
12 Correct 6 ms 852 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 6 ms 848 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 6 ms 852 KB Output is correct
19 Correct 4 ms 596 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 4 ms 596 KB Output is correct
23 Correct 7 ms 852 KB Output is correct
24 Correct 3 ms 584 KB Output is correct
25 Correct 4 ms 856 KB Output is correct
26 Correct 20 ms 856 KB Output is correct
27 Correct 25 ms 852 KB Output is correct
28 Correct 19 ms 916 KB Output is correct
29 Correct 25 ms 852 KB Output is correct
30 Correct 18 ms 964 KB Output is correct
31 Correct 26 ms 852 KB Output is correct
32 Correct 19 ms 848 KB Output is correct
33 Correct 28 ms 852 KB Output is correct
34 Correct 26 ms 852 KB Output is correct
35 Correct 8 ms 596 KB Output is correct
36 Correct 10 ms 636 KB Output is correct
37 Correct 9 ms 588 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 4 ms 980 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 4 ms 980 KB Output is correct
43 Correct 6 ms 980 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 56 ms 8788 KB Output is correct
46 Correct 1631 ms 6956 KB Output is correct
47 Correct 55 ms 8780 KB Output is correct
48 Correct 72 ms 8812 KB Output is correct
49 Correct 23 ms 6260 KB Output is correct
50 Correct 150 ms 9316 KB Output is correct
51 Correct 2564 ms 8852 KB Output is correct
52 Correct 69 ms 5948 KB Output is correct
53 Correct 21 ms 6160 KB Output is correct
54 Correct 21 ms 3284 KB Output is correct
55 Correct 163 ms 9196 KB Output is correct
56 Correct 19 ms 5964 KB Output is correct
57 Correct 70 ms 5936 KB Output is correct
58 Correct 32 ms 6840 KB Output is correct
59 Correct 16 ms 5964 KB Output is correct
60 Correct 1315 ms 5980 KB Output is correct
61 Correct 30 ms 6860 KB Output is correct
62 Correct 2020 ms 6524 KB Output is correct
63 Correct 192 ms 7148 KB Output is correct
64 Correct 1361 ms 5984 KB Output is correct
65 Correct 268 ms 7788 KB Output is correct
66 Correct 2029 ms 6560 KB Output is correct
67 Correct 114 ms 7120 KB Output is correct
68 Correct 2175 ms 7648 KB Output is correct
69 Correct 65 ms 7832 KB Output is correct
70 Correct 2073 ms 6540 KB Output is correct
71 Correct 2230 ms 7648 KB Output is correct
72 Correct 1435 ms 7152 KB Output is correct
73 Correct 2716 ms 8216 KB Output is correct
74 Correct 2040 ms 6596 KB Output is correct
75 Correct 644 ms 3836 KB Output is correct
76 Correct 1472 ms 7204 KB Output is correct
77 Correct 2663 ms 8104 KB Output is correct
78 Correct 692 ms 4248 KB Output is correct
79 Correct 629 ms 3828 KB Output is correct
80 Correct 27 ms 1876 KB Output is correct
81 Correct 671 ms 4244 KB Output is correct
82 Correct 2700 ms 7304 KB Output is correct
83 Correct 26 ms 2124 KB Output is correct
84 Correct 2736 ms 7300 KB Output is correct