답안 #667136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667136 2022-11-30T12:26:40 Z flappybird Political Development (BOI17_politicaldevelopment) C++17
100 / 100
748 ms 37496 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MK 11
vector<int> adj[MAX], add[MAX];
int deg[MAX];
int ord[MAX];
int mp[MK][MK];
int dp[1 << MK];
int bcnt[1 << MK];
int ans = 1;
int valid[MK];
int vis[MAX];
set<pii> alledge;
bool ison[MAX];
void calc(int N) {
	if (!N) return;
	ans = max(ans, 2);
	dp[0] = 1;
	dp[1] = 1;
	int i, j;
	for (i = 1; i < N; i++) {
		int mask = 0;
		for (j = i - 1; j >= 0; j--) {
			mask <<= 1;
			if (mp[i][j]) mask |= 1;
		}
		for (j = 0; j < (1 << i); j++) {
			if (dp[j] && (mask & j) == j) dp[1 << i | j] = 1, ans = max(ans, bcnt[1 << i | j] + 1);
			else dp[1 << i | j] = 0;
		}
	}
}
bool chk(int a, int b) {
	if (alledge.find(pii(a, b)) != alledge.end()) return true;
	if (alledge.find(pii(b, a)) != alledge.end()) return true;
	else return false;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	int i, j, k, a;
	for (i = 0; i < (1 << MK); i++) {
		a = i;
		while (a) {
			bcnt[i] += a & 1;
			a >>= 1;
		}
	}
	queue<int> q;
	for (i = 0; i < N; i++) {
		cin >> deg[i];
		for (j = 0; j < deg[i]; j++) cin >> a, adj[i].push_back(a), alledge.emplace(a, i);
		if (deg[i] < K) q.push(i);
	}
	int cnt = 0;
	while (q.size()) {
		int t = q.front();
		q.pop();
		if (vis[t]) continue;
		vis[t] = 1;
		ord[cnt++] = t;
		for (auto v : adj[t]) {
			deg[v]--;
			if (!vis[v] && deg[v] < K) q.push(v);
		}
	}
	assert(cnt == N);
	for (i = N - 1; i >= 0; i--) {
		int v = ord[i];
		ison[v] = true;
		for (auto x : adj[v]) if (ison[x]) add[v].push_back(x);
		for (j = 0; j < add[v].size(); j++) {
			for (k = j + 1; k < add[v].size(); k++) {
				if (chk(add[v][j], add[v][k])) mp[j][k] = mp[k][j] = 1;
				else mp[j][k] = mp[k][j] = 0;
			}
		}
		assert(add[v].size()<=11);
		calc(add[v].size());
	}
	cout << ans << ln;
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for (j = 0; j < add[v].size(); j++) {
      |               ~~^~~~~~~~~~~~~~~
politicaldevelopment.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |    for (k = j + 1; k < add[v].size(); k++) {
      |                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 9 ms 10580 KB Output is correct
4 Correct 9 ms 10580 KB Output is correct
5 Correct 9 ms 10708 KB Output is correct
6 Correct 12 ms 10684 KB Output is correct
7 Correct 9 ms 10680 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 9 ms 10580 KB Output is correct
4 Correct 9 ms 10580 KB Output is correct
5 Correct 9 ms 10708 KB Output is correct
6 Correct 12 ms 10684 KB Output is correct
7 Correct 9 ms 10680 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9788 KB Output is correct
11 Correct 8 ms 10680 KB Output is correct
12 Correct 8 ms 10720 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 9 ms 10684 KB Output is correct
15 Correct 6 ms 9696 KB Output is correct
16 Correct 9 ms 10708 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 9 ms 10656 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 8 ms 10324 KB Output is correct
21 Correct 8 ms 10296 KB Output is correct
22 Correct 8 ms 9780 KB Output is correct
23 Correct 11 ms 10780 KB Output is correct
24 Correct 6 ms 9784 KB Output is correct
25 Correct 11 ms 10788 KB Output is correct
26 Correct 11 ms 10684 KB Output is correct
27 Correct 10 ms 10552 KB Output is correct
28 Correct 10 ms 10624 KB Output is correct
29 Correct 9 ms 10556 KB Output is correct
30 Correct 13 ms 10872 KB Output is correct
31 Correct 11 ms 10848 KB Output is correct
32 Correct 11 ms 10836 KB Output is correct
33 Correct 12 ms 10836 KB Output is correct
34 Correct 11 ms 10812 KB Output is correct
35 Correct 9 ms 10196 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 8 ms 10196 KB Output is correct
38 Correct 8 ms 10048 KB Output is correct
39 Correct 7 ms 10044 KB Output is correct
40 Correct 15 ms 11136 KB Output is correct
41 Correct 7 ms 10068 KB Output is correct
42 Correct 15 ms 11220 KB Output is correct
43 Correct 15 ms 11124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9764 KB Output is correct
6 Correct 5 ms 9744 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9796 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 692 ms 37496 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 717 ms 37424 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 695 ms 37332 KB Output is correct
16 Correct 748 ms 37452 KB Output is correct
17 Correct 635 ms 37448 KB Output is correct
18 Correct 673 ms 37448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 9 ms 10580 KB Output is correct
4 Correct 9 ms 10580 KB Output is correct
5 Correct 9 ms 10708 KB Output is correct
6 Correct 12 ms 10684 KB Output is correct
7 Correct 9 ms 10680 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9788 KB Output is correct
11 Correct 8 ms 10680 KB Output is correct
12 Correct 8 ms 10720 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 9 ms 10684 KB Output is correct
15 Correct 6 ms 9696 KB Output is correct
16 Correct 9 ms 10708 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 9 ms 10656 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 8 ms 10324 KB Output is correct
21 Correct 8 ms 10296 KB Output is correct
22 Correct 8 ms 9780 KB Output is correct
23 Correct 11 ms 10780 KB Output is correct
24 Correct 6 ms 9784 KB Output is correct
25 Correct 11 ms 10788 KB Output is correct
26 Correct 11 ms 10684 KB Output is correct
27 Correct 10 ms 10552 KB Output is correct
28 Correct 10 ms 10624 KB Output is correct
29 Correct 9 ms 10556 KB Output is correct
30 Correct 13 ms 10872 KB Output is correct
31 Correct 11 ms 10848 KB Output is correct
32 Correct 11 ms 10836 KB Output is correct
33 Correct 12 ms 10836 KB Output is correct
34 Correct 11 ms 10812 KB Output is correct
35 Correct 9 ms 10196 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 8 ms 10196 KB Output is correct
38 Correct 8 ms 10048 KB Output is correct
39 Correct 7 ms 10044 KB Output is correct
40 Correct 15 ms 11136 KB Output is correct
41 Correct 7 ms 10068 KB Output is correct
42 Correct 15 ms 11220 KB Output is correct
43 Correct 15 ms 11124 KB Output is correct
44 Correct 29 ms 12244 KB Output is correct
45 Correct 5 ms 9684 KB Output is correct
46 Correct 16 ms 11220 KB Output is correct
47 Correct 39 ms 12352 KB Output is correct
48 Correct 19 ms 11108 KB Output is correct
49 Correct 32 ms 12376 KB Output is correct
50 Correct 31 ms 12364 KB Output is correct
51 Correct 95 ms 14712 KB Output is correct
52 Correct 10 ms 10708 KB Output is correct
53 Correct 59 ms 15492 KB Output is correct
54 Correct 121 ms 15436 KB Output is correct
55 Correct 10 ms 10736 KB Output is correct
56 Correct 9 ms 10732 KB Output is correct
57 Correct 6 ms 9780 KB Output is correct
58 Correct 57 ms 15500 KB Output is correct
59 Correct 15 ms 11160 KB Output is correct
60 Correct 10 ms 10708 KB Output is correct
61 Correct 14 ms 11200 KB Output is correct
62 Correct 14 ms 11196 KB Output is correct
63 Correct 27 ms 12244 KB Output is correct
64 Correct 23 ms 12016 KB Output is correct
65 Correct 17 ms 11092 KB Output is correct
66 Correct 14 ms 11092 KB Output is correct
67 Correct 40 ms 12864 KB Output is correct
68 Correct 22 ms 12028 KB Output is correct
69 Correct 14 ms 11040 KB Output is correct
70 Correct 28 ms 12096 KB Output is correct
71 Correct 41 ms 12796 KB Output is correct
72 Correct 37 ms 12712 KB Output is correct
73 Correct 11 ms 10552 KB Output is correct
74 Correct 28 ms 12148 KB Output is correct
75 Correct 39 ms 12752 KB Output is correct
76 Correct 20 ms 11552 KB Output is correct
77 Correct 52 ms 13416 KB Output is correct
78 Correct 10 ms 10580 KB Output is correct
79 Correct 34 ms 11592 KB Output is correct
80 Correct 22 ms 11696 KB Output is correct
81 Correct 59 ms 13388 KB Output is correct
82 Correct 8 ms 10204 KB Output is correct
83 Correct 26 ms 11620 KB Output is correct
84 Correct 37 ms 12676 KB Output is correct
85 Correct 7 ms 10044 KB Output is correct
86 Correct 36 ms 12672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9728 KB Output is correct
3 Correct 9 ms 10580 KB Output is correct
4 Correct 9 ms 10580 KB Output is correct
5 Correct 9 ms 10708 KB Output is correct
6 Correct 12 ms 10684 KB Output is correct
7 Correct 9 ms 10680 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9788 KB Output is correct
11 Correct 8 ms 10680 KB Output is correct
12 Correct 8 ms 10720 KB Output is correct
13 Correct 5 ms 9684 KB Output is correct
14 Correct 9 ms 10684 KB Output is correct
15 Correct 6 ms 9696 KB Output is correct
16 Correct 9 ms 10708 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 9 ms 10656 KB Output is correct
19 Correct 6 ms 9812 KB Output is correct
20 Correct 8 ms 10324 KB Output is correct
21 Correct 8 ms 10296 KB Output is correct
22 Correct 8 ms 9780 KB Output is correct
23 Correct 11 ms 10780 KB Output is correct
24 Correct 6 ms 9784 KB Output is correct
25 Correct 11 ms 10788 KB Output is correct
26 Correct 11 ms 10684 KB Output is correct
27 Correct 10 ms 10552 KB Output is correct
28 Correct 10 ms 10624 KB Output is correct
29 Correct 9 ms 10556 KB Output is correct
30 Correct 13 ms 10872 KB Output is correct
31 Correct 11 ms 10848 KB Output is correct
32 Correct 11 ms 10836 KB Output is correct
33 Correct 12 ms 10836 KB Output is correct
34 Correct 11 ms 10812 KB Output is correct
35 Correct 9 ms 10196 KB Output is correct
36 Correct 11 ms 10324 KB Output is correct
37 Correct 8 ms 10196 KB Output is correct
38 Correct 8 ms 10048 KB Output is correct
39 Correct 7 ms 10044 KB Output is correct
40 Correct 15 ms 11136 KB Output is correct
41 Correct 7 ms 10068 KB Output is correct
42 Correct 15 ms 11220 KB Output is correct
43 Correct 15 ms 11124 KB Output is correct
44 Correct 6 ms 9772 KB Output is correct
45 Correct 348 ms 30312 KB Output is correct
46 Correct 107 ms 21440 KB Output is correct
47 Correct 376 ms 30232 KB Output is correct
48 Correct 354 ms 30144 KB Output is correct
49 Correct 43 ms 19048 KB Output is correct
50 Correct 194 ms 35420 KB Output is correct
51 Correct 377 ms 30160 KB Output is correct
52 Correct 55 ms 19020 KB Output is correct
53 Correct 49 ms 19108 KB Output is correct
54 Correct 10 ms 10692 KB Output is correct
55 Correct 201 ms 35544 KB Output is correct
56 Correct 44 ms 15520 KB Output is correct
57 Correct 56 ms 19052 KB Output is correct
58 Correct 105 ms 21136 KB Output is correct
59 Correct 32 ms 15488 KB Output is correct
60 Correct 31 ms 15480 KB Output is correct
61 Correct 115 ms 21164 KB Output is correct
62 Correct 63 ms 18368 KB Output is correct
63 Correct 155 ms 22836 KB Output is correct
64 Correct 32 ms 15544 KB Output is correct
65 Correct 246 ms 25996 KB Output is correct
66 Correct 82 ms 18348 KB Output is correct
67 Correct 151 ms 22896 KB Output is correct
68 Correct 199 ms 24948 KB Output is correct
69 Correct 259 ms 25824 KB Output is correct
70 Correct 77 ms 18356 KB Output is correct
71 Correct 201 ms 25036 KB Output is correct
72 Correct 132 ms 22696 KB Output is correct
73 Correct 291 ms 27496 KB Output is correct
74 Correct 65 ms 18392 KB Output is correct
75 Correct 69 ms 16816 KB Output is correct
76 Correct 129 ms 22500 KB Output is correct
77 Correct 287 ms 27500 KB Output is correct
78 Correct 101 ms 18600 KB Output is correct
79 Correct 69 ms 16768 KB Output is correct
80 Correct 34 ms 13400 KB Output is correct
81 Correct 123 ms 18640 KB Output is correct
82 Correct 190 ms 23884 KB Output is correct
83 Correct 30 ms 13312 KB Output is correct
84 Correct 184 ms 23772 KB Output is correct