답안 #651253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
651253 2022-10-18T03:45:44 Z dooompy Political Development (BOI17_politicaldevelopment) C++17
100 / 100
457 ms 8304 KB
#include <bits/stdc++.h>

using namespace std;

int deg[50005];
vector<int> adj[50005];

set<pair<int, int>> s;
vector<int> neighbours;

bool erased[50005];

int ans = 0;
int sz;

bool check(int mask) {
    for (int i = 0; i < sz; i++) {
        if ((1 << i) & mask) {
            for (int j = 0; j < i; j++) {
                if (( 1 << j ) & mask) {
                    int a = neighbours[i], b = neighbours[j];

                    if (*lower_bound(adj[a].begin(), adj[a].end(), b) != b) return false;
                }
            }
        }
    }

    return true;
}

int main() {
    int n, k; cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> deg[i];
        s.insert({deg[i], i});

        for (int _ = 0; _ < deg[i]; _++) {
            int to; cin >> to;
            adj[i].push_back(to);
        }

        sort(adj[i].begin(), adj[i].end());
    }

    for (int i = 0; i < n; i++) {
        auto cur = *s.begin();
        s.erase(s.begin()); 

        neighbours.clear();
        neighbours.push_back(cur.second);
        for (auto nxt : adj[cur.second]) {
            if (erased[nxt]) continue;
            neighbours.push_back(nxt);
        }

        sz = neighbours.size();

        for (int mask = (1 << sz) - 1; mask >= (1 << ans); mask--) {
            if (__builtin_popcount(mask) <= ans) continue;
            if (check(mask)) ans = __builtin_popcount(mask);
        }

        for (auto nxt : adj[cur.second]) {
            if (erased[nxt]) continue;
            s.erase({deg[nxt], nxt}); deg[nxt]--;
            s.insert({deg[nxt], nxt});
        }

        erased[cur.second] = true;

    }


    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 7 ms 1876 KB Output is correct
4 Correct 8 ms 1968 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 7 ms 1876 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 7 ms 1876 KB Output is correct
4 Correct 8 ms 1968 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 7 ms 1876 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 6 ms 1876 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 7 ms 1908 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 7 ms 1880 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 8 ms 1876 KB Output is correct
19 Correct 3 ms 1752 KB Output is correct
20 Correct 5 ms 1876 KB Output is correct
21 Correct 5 ms 1876 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 9 ms 1876 KB Output is correct
24 Correct 3 ms 1748 KB Output is correct
25 Correct 9 ms 1976 KB Output is correct
26 Correct 8 ms 1876 KB Output is correct
27 Correct 6 ms 1876 KB Output is correct
28 Correct 8 ms 1952 KB Output is correct
29 Correct 7 ms 1876 KB Output is correct
30 Correct 11 ms 1876 KB Output is correct
31 Correct 9 ms 1876 KB Output is correct
32 Correct 11 ms 1876 KB Output is correct
33 Correct 9 ms 1880 KB Output is correct
34 Correct 8 ms 1876 KB Output is correct
35 Correct 6 ms 1620 KB Output is correct
36 Correct 5 ms 1724 KB Output is correct
37 Correct 5 ms 1620 KB Output is correct
38 Correct 4 ms 1620 KB Output is correct
39 Correct 3 ms 1620 KB Output is correct
40 Correct 12 ms 2004 KB Output is correct
41 Correct 3 ms 1620 KB Output is correct
42 Correct 11 ms 2028 KB Output is correct
43 Correct 11 ms 2008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 1 ms 1364 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1364 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1364 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 388 ms 8304 KB Output is correct
12 Correct 1 ms 1364 KB Output is correct
13 Correct 387 ms 8208 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 457 ms 8212 KB Output is correct
16 Correct 378 ms 8268 KB Output is correct
17 Correct 408 ms 8212 KB Output is correct
18 Correct 386 ms 8264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 7 ms 1876 KB Output is correct
4 Correct 8 ms 1968 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 7 ms 1876 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 6 ms 1876 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 7 ms 1908 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 7 ms 1880 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 8 ms 1876 KB Output is correct
19 Correct 3 ms 1752 KB Output is correct
20 Correct 5 ms 1876 KB Output is correct
21 Correct 5 ms 1876 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 9 ms 1876 KB Output is correct
24 Correct 3 ms 1748 KB Output is correct
25 Correct 9 ms 1976 KB Output is correct
26 Correct 8 ms 1876 KB Output is correct
27 Correct 6 ms 1876 KB Output is correct
28 Correct 8 ms 1952 KB Output is correct
29 Correct 7 ms 1876 KB Output is correct
30 Correct 11 ms 1876 KB Output is correct
31 Correct 9 ms 1876 KB Output is correct
32 Correct 11 ms 1876 KB Output is correct
33 Correct 9 ms 1880 KB Output is correct
34 Correct 8 ms 1876 KB Output is correct
35 Correct 6 ms 1620 KB Output is correct
36 Correct 5 ms 1724 KB Output is correct
37 Correct 5 ms 1620 KB Output is correct
38 Correct 4 ms 1620 KB Output is correct
39 Correct 3 ms 1620 KB Output is correct
40 Correct 12 ms 2004 KB Output is correct
41 Correct 3 ms 1620 KB Output is correct
42 Correct 11 ms 2028 KB Output is correct
43 Correct 11 ms 2008 KB Output is correct
44 Correct 17 ms 2160 KB Output is correct
45 Correct 1 ms 1492 KB Output is correct
46 Correct 13 ms 2032 KB Output is correct
47 Correct 24 ms 2140 KB Output is correct
48 Correct 18 ms 2032 KB Output is correct
49 Correct 26 ms 2132 KB Output is correct
50 Correct 24 ms 2136 KB Output is correct
51 Correct 129 ms 2492 KB Output is correct
52 Correct 6 ms 1876 KB Output is correct
53 Correct 285 ms 2588 KB Output is correct
54 Correct 219 ms 2556 KB Output is correct
55 Correct 7 ms 1876 KB Output is correct
56 Correct 6 ms 1876 KB Output is correct
57 Correct 3 ms 1748 KB Output is correct
58 Correct 292 ms 2636 KB Output is correct
59 Correct 10 ms 1880 KB Output is correct
60 Correct 7 ms 1876 KB Output is correct
61 Correct 9 ms 2004 KB Output is correct
62 Correct 9 ms 1888 KB Output is correct
63 Correct 16 ms 2140 KB Output is correct
64 Correct 15 ms 2124 KB Output is correct
65 Correct 11 ms 2004 KB Output is correct
66 Correct 10 ms 2004 KB Output is correct
67 Correct 33 ms 2264 KB Output is correct
68 Correct 16 ms 2136 KB Output is correct
69 Correct 13 ms 1896 KB Output is correct
70 Correct 20 ms 2148 KB Output is correct
71 Correct 33 ms 2316 KB Output is correct
72 Correct 29 ms 2240 KB Output is correct
73 Correct 7 ms 1876 KB Output is correct
74 Correct 20 ms 2132 KB Output is correct
75 Correct 29 ms 2260 KB Output is correct
76 Correct 16 ms 2004 KB Output is correct
77 Correct 68 ms 2252 KB Output is correct
78 Correct 7 ms 1876 KB Output is correct
79 Correct 36 ms 1912 KB Output is correct
80 Correct 15 ms 2024 KB Output is correct
81 Correct 68 ms 2388 KB Output is correct
82 Correct 4 ms 1576 KB Output is correct
83 Correct 33 ms 1876 KB Output is correct
84 Correct 32 ms 2264 KB Output is correct
85 Correct 4 ms 1620 KB Output is correct
86 Correct 23 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1364 KB Output is correct
3 Correct 7 ms 1876 KB Output is correct
4 Correct 8 ms 1968 KB Output is correct
5 Correct 7 ms 1876 KB Output is correct
6 Correct 7 ms 1880 KB Output is correct
7 Correct 7 ms 1876 KB Output is correct
8 Correct 3 ms 1748 KB Output is correct
9 Correct 1 ms 1364 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 6 ms 1876 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 2 ms 1492 KB Output is correct
14 Correct 7 ms 1908 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 7 ms 1880 KB Output is correct
17 Correct 1 ms 1364 KB Output is correct
18 Correct 8 ms 1876 KB Output is correct
19 Correct 3 ms 1752 KB Output is correct
20 Correct 5 ms 1876 KB Output is correct
21 Correct 5 ms 1876 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 9 ms 1876 KB Output is correct
24 Correct 3 ms 1748 KB Output is correct
25 Correct 9 ms 1976 KB Output is correct
26 Correct 8 ms 1876 KB Output is correct
27 Correct 6 ms 1876 KB Output is correct
28 Correct 8 ms 1952 KB Output is correct
29 Correct 7 ms 1876 KB Output is correct
30 Correct 11 ms 1876 KB Output is correct
31 Correct 9 ms 1876 KB Output is correct
32 Correct 11 ms 1876 KB Output is correct
33 Correct 9 ms 1880 KB Output is correct
34 Correct 8 ms 1876 KB Output is correct
35 Correct 6 ms 1620 KB Output is correct
36 Correct 5 ms 1724 KB Output is correct
37 Correct 5 ms 1620 KB Output is correct
38 Correct 4 ms 1620 KB Output is correct
39 Correct 3 ms 1620 KB Output is correct
40 Correct 12 ms 2004 KB Output is correct
41 Correct 3 ms 1620 KB Output is correct
42 Correct 11 ms 2028 KB Output is correct
43 Correct 11 ms 2008 KB Output is correct
44 Correct 1 ms 1364 KB Output is correct
45 Correct 193 ms 6628 KB Output is correct
46 Correct 92 ms 5956 KB Output is correct
47 Correct 216 ms 6572 KB Output is correct
48 Correct 215 ms 6604 KB Output is correct
49 Correct 64 ms 5968 KB Output is correct
50 Correct 239 ms 6680 KB Output is correct
51 Correct 210 ms 6604 KB Output is correct
52 Correct 62 ms 6004 KB Output is correct
53 Correct 65 ms 6052 KB Output is correct
54 Correct 19 ms 4064 KB Output is correct
55 Correct 249 ms 6800 KB Output is correct
56 Correct 45 ms 5836 KB Output is correct
57 Correct 62 ms 6040 KB Output is correct
58 Correct 81 ms 5796 KB Output is correct
59 Correct 43 ms 5840 KB Output is correct
60 Correct 44 ms 5768 KB Output is correct
61 Correct 85 ms 5792 KB Output is correct
62 Correct 63 ms 5824 KB Output is correct
63 Correct 124 ms 5956 KB Output is correct
64 Correct 42 ms 5836 KB Output is correct
65 Correct 149 ms 6184 KB Output is correct
66 Correct 76 ms 5804 KB Output is correct
67 Correct 121 ms 5996 KB Output is correct
68 Correct 151 ms 6228 KB Output is correct
69 Correct 172 ms 6480 KB Output is correct
70 Correct 69 ms 5836 KB Output is correct
71 Correct 144 ms 6120 KB Output is correct
72 Correct 104 ms 6164 KB Output is correct
73 Correct 185 ms 6380 KB Output is correct
74 Correct 70 ms 5836 KB Output is correct
75 Correct 62 ms 3788 KB Output is correct
76 Correct 108 ms 6012 KB Output is correct
77 Correct 184 ms 6368 KB Output is correct
78 Correct 88 ms 4096 KB Output is correct
79 Correct 61 ms 3888 KB Output is correct
80 Correct 28 ms 2864 KB Output is correct
81 Correct 82 ms 4044 KB Output is correct
82 Correct 125 ms 5856 KB Output is correct
83 Correct 29 ms 2772 KB Output is correct
84 Correct 128 ms 5964 KB Output is correct