답안 #248889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248889 2020-07-13T17:08:05 Z Tc14 Political Development (BOI17_politicaldevelopment) C++17
100 / 100
159 ms 24312 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ve vector
typedef long long ll;

int ans;
ve<int> S, T;
ve<set<int>> G;

void f(int i, int s) {

    bool valid;

    if (i < S.size()) {

        f(i + 1, s);

        valid = true;
        for (int t : T) {
            if (G[t].find(S[i]) == G[t].end()) {
                valid = false;
                break;
            }
        }

        if (valid) {
            T.push_back(S[i]);
            f(i + 1, s + 1);
            T.pop_back();
        }
    }
    else ans = max(ans, s);

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k, d, a, u;
    ve<int> D;
    ve<bool> I;
    queue<int> Q;

    cin >> n >> k;
    G = ve<set<int>>(n);
    D = ve<int>(n);
    I = ve<bool>(n);

    for (int i = 0; i < n; i++) {
        cin >> d;
        D[i] = d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            G[i].insert(a);
        }
        if (d < k) {
            Q.push(i);
            I[i] = true;
        }
    }

    ans = 0;
    for (int i = 0; i < n; i++) {
        u = Q.front();
        Q.pop();
        S.clear();
        for (int v : G[u]) {
            if (D[v] > 0) {
                D[v]--;
                S.push_back(v);
                if (D[v] < k && !I[v]) {
                    Q.push(v);
                    I[v] = true;
                }
            }
        }
        D[u] = 0;
        f(0, 1);
    }

    cout << ans << endl;

    return 0;
}

Compilation message

politicaldevelopment.cpp: In function 'void f(int, int)':
politicaldevelopment.cpp:15:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i < S.size()) {
         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 3 ms 896 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 4 ms 1152 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 3 ms 1152 KB Output is correct
29 Correct 4 ms 1152 KB Output is correct
30 Correct 6 ms 1280 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 6 ms 1280 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 3 ms 1280 KB Output is correct
35 Correct 2 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 2 ms 768 KB Output is correct
38 Correct 2 ms 640 KB Output is correct
39 Correct 1 ms 640 KB Output is correct
40 Correct 5 ms 1536 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 5 ms 1536 KB Output is correct
43 Correct 6 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 155 ms 24184 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 159 ms 24312 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 159 ms 24184 KB Output is correct
16 Correct 154 ms 24184 KB Output is correct
17 Correct 154 ms 24184 KB Output is correct
18 Correct 150 ms 24184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 3 ms 896 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 4 ms 1152 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 3 ms 1152 KB Output is correct
29 Correct 4 ms 1152 KB Output is correct
30 Correct 6 ms 1280 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 6 ms 1280 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 3 ms 1280 KB Output is correct
35 Correct 2 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 2 ms 768 KB Output is correct
38 Correct 2 ms 640 KB Output is correct
39 Correct 1 ms 640 KB Output is correct
40 Correct 5 ms 1536 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 5 ms 1536 KB Output is correct
43 Correct 6 ms 1536 KB Output is correct
44 Correct 20 ms 2560 KB Output is correct
45 Correct 0 ms 384 KB Output is correct
46 Correct 6 ms 1536 KB Output is correct
47 Correct 13 ms 2712 KB Output is correct
48 Correct 7 ms 1664 KB Output is correct
49 Correct 12 ms 2688 KB Output is correct
50 Correct 13 ms 2688 KB Output is correct
51 Correct 31 ms 4736 KB Output is correct
52 Correct 3 ms 1152 KB Output is correct
53 Correct 33 ms 5240 KB Output is correct
54 Correct 33 ms 5248 KB Output is correct
55 Correct 3 ms 1152 KB Output is correct
56 Correct 3 ms 1152 KB Output is correct
57 Correct 1 ms 640 KB Output is correct
58 Correct 31 ms 5248 KB Output is correct
59 Correct 6 ms 1664 KB Output is correct
60 Correct 3 ms 1152 KB Output is correct
61 Correct 5 ms 1664 KB Output is correct
62 Correct 6 ms 1664 KB Output is correct
63 Correct 19 ms 2688 KB Output is correct
64 Correct 13 ms 2432 KB Output is correct
65 Correct 5 ms 1536 KB Output is correct
66 Correct 5 ms 1664 KB Output is correct
67 Correct 19 ms 3072 KB Output is correct
68 Correct 13 ms 2432 KB Output is correct
69 Correct 5 ms 1536 KB Output is correct
70 Correct 11 ms 2432 KB Output is correct
71 Correct 20 ms 3072 KB Output is correct
72 Correct 17 ms 3072 KB Output is correct
73 Correct 3 ms 1152 KB Output is correct
74 Correct 13 ms 2560 KB Output is correct
75 Correct 16 ms 3072 KB Output is correct
76 Correct 11 ms 2048 KB Output is correct
77 Correct 26 ms 3584 KB Output is correct
78 Correct 5 ms 1152 KB Output is correct
79 Correct 9 ms 1920 KB Output is correct
80 Correct 12 ms 2048 KB Output is correct
81 Correct 18 ms 3584 KB Output is correct
82 Correct 2 ms 640 KB Output is correct
83 Correct 10 ms 1920 KB Output is correct
84 Correct 12 ms 2944 KB Output is correct
85 Correct 1 ms 640 KB Output is correct
86 Correct 12 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 3 ms 1152 KB Output is correct
6 Correct 4 ms 1024 KB Output is correct
7 Correct 3 ms 1152 KB Output is correct
8 Correct 1 ms 640 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1152 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 3 ms 1152 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 3 ms 1152 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 3 ms 1152 KB Output is correct
19 Correct 1 ms 640 KB Output is correct
20 Correct 3 ms 896 KB Output is correct
21 Correct 2 ms 896 KB Output is correct
22 Correct 1 ms 640 KB Output is correct
23 Correct 4 ms 1152 KB Output is correct
24 Correct 1 ms 640 KB Output is correct
25 Correct 4 ms 1152 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 4 ms 1152 KB Output is correct
28 Correct 3 ms 1152 KB Output is correct
29 Correct 4 ms 1152 KB Output is correct
30 Correct 6 ms 1280 KB Output is correct
31 Correct 4 ms 1280 KB Output is correct
32 Correct 6 ms 1280 KB Output is correct
33 Correct 5 ms 1280 KB Output is correct
34 Correct 3 ms 1280 KB Output is correct
35 Correct 2 ms 768 KB Output is correct
36 Correct 2 ms 768 KB Output is correct
37 Correct 2 ms 768 KB Output is correct
38 Correct 2 ms 640 KB Output is correct
39 Correct 1 ms 640 KB Output is correct
40 Correct 5 ms 1536 KB Output is correct
41 Correct 1 ms 640 KB Output is correct
42 Correct 5 ms 1536 KB Output is correct
43 Correct 6 ms 1536 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 95 ms 17016 KB Output is correct
46 Correct 47 ms 10104 KB Output is correct
47 Correct 110 ms 17140 KB Output is correct
48 Correct 98 ms 18848 KB Output is correct
49 Correct 36 ms 8440 KB Output is correct
50 Correct 147 ms 24276 KB Output is correct
51 Correct 109 ms 18936 KB Output is correct
52 Correct 30 ms 8448 KB Output is correct
53 Correct 37 ms 8440 KB Output is correct
54 Correct 5 ms 3200 KB Output is correct
55 Correct 146 ms 24184 KB Output is correct
56 Correct 15 ms 6016 KB Output is correct
57 Correct 30 ms 8440 KB Output is correct
58 Correct 39 ms 11128 KB Output is correct
59 Correct 15 ms 5888 KB Output is correct
60 Correct 15 ms 5888 KB Output is correct
61 Correct 43 ms 11168 KB Output is correct
62 Correct 29 ms 8448 KB Output is correct
63 Correct 57 ms 12280 KB Output is correct
64 Correct 14 ms 5888 KB Output is correct
65 Correct 76 ms 14968 KB Output is correct
66 Correct 29 ms 8440 KB Output is correct
67 Correct 57 ms 12280 KB Output is correct
68 Correct 65 ms 14328 KB Output is correct
69 Correct 82 ms 14968 KB Output is correct
70 Correct 29 ms 8448 KB Output is correct
71 Correct 70 ms 14328 KB Output is correct
72 Correct 57 ms 11896 KB Output is correct
73 Correct 82 ms 16588 KB Output is correct
74 Correct 31 ms 8440 KB Output is correct
75 Correct 27 ms 6784 KB Output is correct
76 Correct 56 ms 11896 KB Output is correct
77 Correct 92 ms 16632 KB Output is correct
78 Correct 39 ms 8440 KB Output is correct
79 Correct 35 ms 6776 KB Output is correct
80 Correct 14 ms 3584 KB Output is correct
81 Correct 38 ms 8448 KB Output is correct
82 Correct 60 ms 13692 KB Output is correct
83 Correct 15 ms 3584 KB Output is correct
84 Correct 60 ms 13688 KB Output is correct