답안 #478057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478057 2021-10-05T12:39:18 Z Sohsoh84 Political Development (BOI17_politicaldevelopment) C++17
100 / 100
431 ms 74312 KB
// ?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;

set<int> adj[MAXN];
set<pll> st;
int n, k, ans = 1, msk_adj[MAXN];
bool dp[MAXN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		int d;
		cin >> d;
		for (int j = 1; j <= d; j++) {
			int v;
			cin >> v;
			v++;
			adj[i].insert(v);
		}
		
		st.insert({adj[i].size(), i});
	}

	while (!st.empty()) {
		int v = st.begin() -> Y;
		st.erase(st.begin());

		vector<int> vec;
		for (int e : adj[v]) {
			st.erase({adj[e].size(), e});
			adj[e].erase(v);
			vec.push_back(e);
			st.insert({adj[e].size(), e});
		}

		int sz = vec.size();
		for (int i = 0; i < sz; i++)
			for (int j = 0; j < sz; j++)
				msk_adj[i] ^= (adj[vec[i]].find(vec[j]) == adj[vec[i]].end() ? 0 : (1 << j));

		dp[0] = true;
		for (int msk = 1; msk < (1 << sz); msk++) {
			int ind = __builtin_ctz(msk), tmsk = msk - (1 << ind);
			dp[msk] = (dp[tmsk] && (tmsk & msk_adj[ind]) == tmsk);
		
			if (dp[msk]) ans = max(ans, __builtin_popcount(msk) + 1);
		}

		for (int i = 0; i < sz; i++) msk_adj[i] = 0;

	}

	cout << ans << endl;
	return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47184 KB Output is correct
2 Correct 25 ms 47252 KB Output is correct
3 Correct 31 ms 47948 KB Output is correct
4 Correct 28 ms 48008 KB Output is correct
5 Correct 28 ms 47948 KB Output is correct
6 Correct 28 ms 48076 KB Output is correct
7 Correct 29 ms 47948 KB Output is correct
8 Correct 28 ms 47564 KB Output is correct
9 Correct 26 ms 47252 KB Output is correct
10 Correct 25 ms 47596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47184 KB Output is correct
2 Correct 25 ms 47252 KB Output is correct
3 Correct 31 ms 47948 KB Output is correct
4 Correct 28 ms 48008 KB Output is correct
5 Correct 28 ms 47948 KB Output is correct
6 Correct 28 ms 48076 KB Output is correct
7 Correct 29 ms 47948 KB Output is correct
8 Correct 28 ms 47564 KB Output is correct
9 Correct 26 ms 47252 KB Output is correct
10 Correct 25 ms 47596 KB Output is correct
11 Correct 31 ms 48076 KB Output is correct
12 Correct 31 ms 48012 KB Output is correct
13 Correct 24 ms 47180 KB Output is correct
14 Correct 30 ms 48080 KB Output is correct
15 Correct 26 ms 47260 KB Output is correct
16 Correct 33 ms 48076 KB Output is correct
17 Correct 24 ms 47180 KB Output is correct
18 Correct 31 ms 48072 KB Output is correct
19 Correct 27 ms 47584 KB Output is correct
20 Correct 30 ms 47728 KB Output is correct
21 Correct 29 ms 47820 KB Output is correct
22 Correct 27 ms 47548 KB Output is correct
23 Correct 30 ms 48084 KB Output is correct
24 Correct 25 ms 47564 KB Output is correct
25 Correct 35 ms 48100 KB Output is correct
26 Correct 30 ms 48104 KB Output is correct
27 Correct 29 ms 48052 KB Output is correct
28 Correct 29 ms 48068 KB Output is correct
29 Correct 30 ms 48076 KB Output is correct
30 Correct 30 ms 48204 KB Output is correct
31 Correct 31 ms 48212 KB Output is correct
32 Correct 33 ms 48120 KB Output is correct
33 Correct 31 ms 48148 KB Output is correct
34 Correct 30 ms 48204 KB Output is correct
35 Correct 28 ms 47720 KB Output is correct
36 Correct 27 ms 47856 KB Output is correct
37 Correct 28 ms 47696 KB Output is correct
38 Correct 27 ms 47544 KB Output is correct
39 Correct 30 ms 47524 KB Output is correct
40 Correct 38 ms 48460 KB Output is correct
41 Correct 28 ms 47552 KB Output is correct
42 Correct 37 ms 48520 KB Output is correct
43 Correct 39 ms 48460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 47692 KB Output is correct
2 Correct 26 ms 47196 KB Output is correct
3 Correct 25 ms 47296 KB Output is correct
4 Correct 24 ms 47236 KB Output is correct
5 Correct 24 ms 47216 KB Output is correct
6 Correct 25 ms 47180 KB Output is correct
7 Correct 25 ms 47276 KB Output is correct
8 Correct 25 ms 47176 KB Output is correct
9 Correct 26 ms 47196 KB Output is correct
10 Correct 27 ms 47292 KB Output is correct
11 Correct 426 ms 74188 KB Output is correct
12 Correct 23 ms 47184 KB Output is correct
13 Correct 411 ms 74132 KB Output is correct
14 Correct 25 ms 47184 KB Output is correct
15 Correct 381 ms 74252 KB Output is correct
16 Correct 410 ms 74184 KB Output is correct
17 Correct 429 ms 74284 KB Output is correct
18 Correct 431 ms 74312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47184 KB Output is correct
2 Correct 25 ms 47252 KB Output is correct
3 Correct 31 ms 47948 KB Output is correct
4 Correct 28 ms 48008 KB Output is correct
5 Correct 28 ms 47948 KB Output is correct
6 Correct 28 ms 48076 KB Output is correct
7 Correct 29 ms 47948 KB Output is correct
8 Correct 28 ms 47564 KB Output is correct
9 Correct 26 ms 47252 KB Output is correct
10 Correct 25 ms 47596 KB Output is correct
11 Correct 31 ms 48076 KB Output is correct
12 Correct 31 ms 48012 KB Output is correct
13 Correct 24 ms 47180 KB Output is correct
14 Correct 30 ms 48080 KB Output is correct
15 Correct 26 ms 47260 KB Output is correct
16 Correct 33 ms 48076 KB Output is correct
17 Correct 24 ms 47180 KB Output is correct
18 Correct 31 ms 48072 KB Output is correct
19 Correct 27 ms 47584 KB Output is correct
20 Correct 30 ms 47728 KB Output is correct
21 Correct 29 ms 47820 KB Output is correct
22 Correct 27 ms 47548 KB Output is correct
23 Correct 30 ms 48084 KB Output is correct
24 Correct 25 ms 47564 KB Output is correct
25 Correct 35 ms 48100 KB Output is correct
26 Correct 30 ms 48104 KB Output is correct
27 Correct 29 ms 48052 KB Output is correct
28 Correct 29 ms 48068 KB Output is correct
29 Correct 30 ms 48076 KB Output is correct
30 Correct 30 ms 48204 KB Output is correct
31 Correct 31 ms 48212 KB Output is correct
32 Correct 33 ms 48120 KB Output is correct
33 Correct 31 ms 48148 KB Output is correct
34 Correct 30 ms 48204 KB Output is correct
35 Correct 28 ms 47720 KB Output is correct
36 Correct 27 ms 47856 KB Output is correct
37 Correct 28 ms 47696 KB Output is correct
38 Correct 27 ms 47544 KB Output is correct
39 Correct 30 ms 47524 KB Output is correct
40 Correct 38 ms 48460 KB Output is correct
41 Correct 28 ms 47552 KB Output is correct
42 Correct 37 ms 48520 KB Output is correct
43 Correct 39 ms 48460 KB Output is correct
44 Correct 45 ms 49476 KB Output is correct
45 Correct 23 ms 47284 KB Output is correct
46 Correct 34 ms 48584 KB Output is correct
47 Correct 48 ms 49612 KB Output is correct
48 Correct 36 ms 48592 KB Output is correct
49 Correct 50 ms 49660 KB Output is correct
50 Correct 48 ms 49624 KB Output is correct
51 Correct 79 ms 51732 KB Output is correct
52 Correct 30 ms 48132 KB Output is correct
53 Correct 74 ms 52224 KB Output is correct
54 Correct 91 ms 52204 KB Output is correct
55 Correct 29 ms 48080 KB Output is correct
56 Correct 33 ms 48080 KB Output is correct
57 Correct 26 ms 47548 KB Output is correct
58 Correct 73 ms 52248 KB Output is correct
59 Correct 36 ms 48584 KB Output is correct
60 Correct 33 ms 48072 KB Output is correct
61 Correct 32 ms 48592 KB Output is correct
62 Correct 32 ms 48584 KB Output is correct
63 Correct 45 ms 49664 KB Output is correct
64 Correct 40 ms 49364 KB Output is correct
65 Correct 33 ms 48452 KB Output is correct
66 Correct 36 ms 48592 KB Output is correct
67 Correct 55 ms 49992 KB Output is correct
68 Correct 38 ms 49360 KB Output is correct
69 Correct 35 ms 48464 KB Output is correct
70 Correct 48 ms 49360 KB Output is correct
71 Correct 53 ms 50000 KB Output is correct
72 Correct 48 ms 49996 KB Output is correct
73 Correct 29 ms 48148 KB Output is correct
74 Correct 45 ms 49432 KB Output is correct
75 Correct 55 ms 49932 KB Output is correct
76 Correct 42 ms 48908 KB Output is correct
77 Correct 59 ms 50516 KB Output is correct
78 Correct 28 ms 48072 KB Output is correct
79 Correct 43 ms 49032 KB Output is correct
80 Correct 37 ms 48968 KB Output is correct
81 Correct 60 ms 50504 KB Output is correct
82 Correct 29 ms 47488 KB Output is correct
83 Correct 46 ms 49040 KB Output is correct
84 Correct 50 ms 50000 KB Output is correct
85 Correct 30 ms 47556 KB Output is correct
86 Correct 50 ms 49912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 47184 KB Output is correct
2 Correct 25 ms 47252 KB Output is correct
3 Correct 31 ms 47948 KB Output is correct
4 Correct 28 ms 48008 KB Output is correct
5 Correct 28 ms 47948 KB Output is correct
6 Correct 28 ms 48076 KB Output is correct
7 Correct 29 ms 47948 KB Output is correct
8 Correct 28 ms 47564 KB Output is correct
9 Correct 26 ms 47252 KB Output is correct
10 Correct 25 ms 47596 KB Output is correct
11 Correct 31 ms 48076 KB Output is correct
12 Correct 31 ms 48012 KB Output is correct
13 Correct 24 ms 47180 KB Output is correct
14 Correct 30 ms 48080 KB Output is correct
15 Correct 26 ms 47260 KB Output is correct
16 Correct 33 ms 48076 KB Output is correct
17 Correct 24 ms 47180 KB Output is correct
18 Correct 31 ms 48072 KB Output is correct
19 Correct 27 ms 47584 KB Output is correct
20 Correct 30 ms 47728 KB Output is correct
21 Correct 29 ms 47820 KB Output is correct
22 Correct 27 ms 47548 KB Output is correct
23 Correct 30 ms 48084 KB Output is correct
24 Correct 25 ms 47564 KB Output is correct
25 Correct 35 ms 48100 KB Output is correct
26 Correct 30 ms 48104 KB Output is correct
27 Correct 29 ms 48052 KB Output is correct
28 Correct 29 ms 48068 KB Output is correct
29 Correct 30 ms 48076 KB Output is correct
30 Correct 30 ms 48204 KB Output is correct
31 Correct 31 ms 48212 KB Output is correct
32 Correct 33 ms 48120 KB Output is correct
33 Correct 31 ms 48148 KB Output is correct
34 Correct 30 ms 48204 KB Output is correct
35 Correct 28 ms 47720 KB Output is correct
36 Correct 27 ms 47856 KB Output is correct
37 Correct 28 ms 47696 KB Output is correct
38 Correct 27 ms 47544 KB Output is correct
39 Correct 30 ms 47524 KB Output is correct
40 Correct 38 ms 48460 KB Output is correct
41 Correct 28 ms 47552 KB Output is correct
42 Correct 37 ms 48520 KB Output is correct
43 Correct 39 ms 48460 KB Output is correct
44 Correct 26 ms 47176 KB Output is correct
45 Correct 276 ms 64500 KB Output is correct
46 Correct 146 ms 57508 KB Output is correct
47 Correct 290 ms 64480 KB Output is correct
48 Correct 295 ms 64580 KB Output is correct
49 Correct 87 ms 55104 KB Output is correct
50 Correct 277 ms 69088 KB Output is correct
51 Correct 278 ms 64476 KB Output is correct
52 Correct 83 ms 55024 KB Output is correct
53 Correct 91 ms 55040 KB Output is correct
54 Correct 39 ms 50372 KB Output is correct
55 Correct 302 ms 69192 KB Output is correct
56 Correct 57 ms 52672 KB Output is correct
57 Correct 90 ms 55108 KB Output is correct
58 Correct 100 ms 57500 KB Output is correct
59 Correct 60 ms 53064 KB Output is correct
60 Correct 60 ms 53136 KB Output is correct
61 Correct 103 ms 58392 KB Output is correct
62 Correct 83 ms 55744 KB Output is correct
63 Correct 162 ms 59728 KB Output is correct
64 Correct 57 ms 53220 KB Output is correct
65 Correct 207 ms 62260 KB Output is correct
66 Correct 76 ms 55752 KB Output is correct
67 Correct 163 ms 59776 KB Output is correct
68 Correct 186 ms 61632 KB Output is correct
69 Correct 210 ms 62256 KB Output is correct
70 Correct 80 ms 55708 KB Output is correct
71 Correct 206 ms 61768 KB Output is correct
72 Correct 140 ms 59288 KB Output is correct
73 Correct 230 ms 63984 KB Output is correct
74 Correct 84 ms 55804 KB Output is correct
75 Correct 90 ms 53896 KB Output is correct
76 Correct 133 ms 59208 KB Output is correct
77 Correct 223 ms 64008 KB Output is correct
78 Correct 111 ms 55624 KB Output is correct
79 Correct 87 ms 53896 KB Output is correct
80 Correct 56 ms 50632 KB Output is correct
81 Correct 128 ms 55632 KB Output is correct
82 Correct 180 ms 61028 KB Output is correct
83 Correct 57 ms 50628 KB Output is correct
84 Correct 174 ms 61028 KB Output is correct