Submission #567350

# Submission time Handle Problem Language Result Execution time Memory
567350 2022-05-23T10:47:13 Z SavicS Political Development (BOI17_politicaldevelopment) C++17
100 / 100
1521 ms 37120 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ldb;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ldb,ldb> pdd;

#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(a) (int)(a).size()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

const int mod = 1000000007;
const int inf = 1e9 + 5;
const int mxN = 50005; 

int n, K;

vector<int> g[mxN];
int deg[mxN];

bool los[mxN];

int dp[(1 << 11)];
int msk[(1 << 11)];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> K; 

    map<pii,bool> ima;
    ff(i,1,n){
        int len;
        cin >> len;
        ff(j,1,len){
            int X;
            cin >> X; X++;
            g[i].pb(X); deg[i] += 1;
            ima[{i, X}] = ima[{X, i}] = 1;
        }
    }

    set<pii> s;
    ff(i,1,n)s.insert({deg[i], i});

    int rez = 0;
    while(sz(s)){
        pii X = *s.begin(); s.erase(X); deg[X.se] = 0;

        vector<int> vec; vec.pb(X.se);
        for(auto c : g[X.se]){
            if(deg[c] > 0){
                vec.pb(c);
            }
        }

        int L = sz(vec); // assert(L <= 10);

        ff(i,0,L - 1){
            msk[(1 << i)] = (1 << i);
            ff(j,0,L - 1){
                if(ima.count({vec[i], vec[j]}) == 1){
                    msk[(1 << i)] |= (1 << j);
                }
            }
        }

        dp[0] = (1 << L) - 1;
        ff(mask,1,(1 << L) - 1){
            int j = mask & (-mask);
            dp[mask] = dp[mask ^ j] & msk[j];
        }        

        ff(mask,1,(1 << L) - 1){
            if((dp[mask] & mask) == mask){
                rez = max(rez, __builtin_popcount(mask));
            }
        }

        ff(i,1,L - 1){
            int A = vec[i];
            s.erase({deg[A], A});
            deg[A] -= 1;
            if(deg[A] > 0)s.insert({deg[A], A});
        }

    }

    cout << rez << '\n';

    return 0;
}
/*

5 3
2 1 2
3 0 2 3
3 0 1 4
2 1 4
2 2 3

// probati bojenje sahovski
*/
 
 
 
 
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 15 ms 2608 KB Output is correct
4 Correct 9 ms 2612 KB Output is correct
5 Correct 9 ms 2516 KB Output is correct
6 Correct 12 ms 2644 KB Output is correct
7 Correct 13 ms 2592 KB Output is correct
8 Correct 4 ms 1748 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 15 ms 2608 KB Output is correct
4 Correct 9 ms 2612 KB Output is correct
5 Correct 9 ms 2516 KB Output is correct
6 Correct 12 ms 2644 KB Output is correct
7 Correct 13 ms 2592 KB Output is correct
8 Correct 4 ms 1748 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 9 ms 2540 KB Output is correct
12 Correct 9 ms 2516 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 14 ms 2516 KB Output is correct
15 Correct 2 ms 1500 KB Output is correct
16 Correct 12 ms 2540 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 13 ms 2644 KB Output is correct
19 Correct 3 ms 1748 KB Output is correct
20 Correct 6 ms 2260 KB Output is correct
21 Correct 7 ms 2260 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 19 ms 2672 KB Output is correct
24 Correct 4 ms 1748 KB Output is correct
25 Correct 23 ms 2792 KB Output is correct
26 Correct 14 ms 2664 KB Output is correct
27 Correct 16 ms 2516 KB Output is correct
28 Correct 20 ms 2692 KB Output is correct
29 Correct 17 ms 2600 KB Output is correct
30 Correct 25 ms 2844 KB Output is correct
31 Correct 22 ms 2756 KB Output is correct
32 Correct 16 ms 2804 KB Output is correct
33 Correct 16 ms 2804 KB Output is correct
34 Correct 20 ms 2772 KB Output is correct
35 Correct 10 ms 2132 KB Output is correct
36 Correct 8 ms 2132 KB Output is correct
37 Correct 9 ms 2132 KB Output is correct
38 Correct 6 ms 1904 KB Output is correct
39 Correct 8 ms 1920 KB Output is correct
40 Correct 35 ms 3284 KB Output is correct
41 Correct 8 ms 1944 KB Output is correct
42 Correct 28 ms 3284 KB Output is correct
43 Correct 33 ms 3204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1772 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 3 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 2 ms 1500 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 1320 ms 37020 KB Output is correct
12 Correct 2 ms 1520 KB Output is correct
13 Correct 1498 ms 37028 KB Output is correct
14 Correct 3 ms 1492 KB Output is correct
15 Correct 1521 ms 37020 KB Output is correct
16 Correct 1433 ms 37120 KB Output is correct
17 Correct 1412 ms 37020 KB Output is correct
18 Correct 1518 ms 37024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 15 ms 2608 KB Output is correct
4 Correct 9 ms 2612 KB Output is correct
5 Correct 9 ms 2516 KB Output is correct
6 Correct 12 ms 2644 KB Output is correct
7 Correct 13 ms 2592 KB Output is correct
8 Correct 4 ms 1748 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 9 ms 2540 KB Output is correct
12 Correct 9 ms 2516 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 14 ms 2516 KB Output is correct
15 Correct 2 ms 1500 KB Output is correct
16 Correct 12 ms 2540 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 13 ms 2644 KB Output is correct
19 Correct 3 ms 1748 KB Output is correct
20 Correct 6 ms 2260 KB Output is correct
21 Correct 7 ms 2260 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 19 ms 2672 KB Output is correct
24 Correct 4 ms 1748 KB Output is correct
25 Correct 23 ms 2792 KB Output is correct
26 Correct 14 ms 2664 KB Output is correct
27 Correct 16 ms 2516 KB Output is correct
28 Correct 20 ms 2692 KB Output is correct
29 Correct 17 ms 2600 KB Output is correct
30 Correct 25 ms 2844 KB Output is correct
31 Correct 22 ms 2756 KB Output is correct
32 Correct 16 ms 2804 KB Output is correct
33 Correct 16 ms 2804 KB Output is correct
34 Correct 20 ms 2772 KB Output is correct
35 Correct 10 ms 2132 KB Output is correct
36 Correct 8 ms 2132 KB Output is correct
37 Correct 9 ms 2132 KB Output is correct
38 Correct 6 ms 1904 KB Output is correct
39 Correct 8 ms 1920 KB Output is correct
40 Correct 35 ms 3284 KB Output is correct
41 Correct 8 ms 1944 KB Output is correct
42 Correct 28 ms 3284 KB Output is correct
43 Correct 33 ms 3204 KB Output is correct
44 Correct 52 ms 4696 KB Output is correct
45 Correct 2 ms 1492 KB Output is correct
46 Correct 35 ms 3300 KB Output is correct
47 Correct 69 ms 4748 KB Output is correct
48 Correct 33 ms 3264 KB Output is correct
49 Correct 66 ms 4744 KB Output is correct
50 Correct 71 ms 4704 KB Output is correct
51 Correct 159 ms 7664 KB Output is correct
52 Correct 9 ms 2636 KB Output is correct
53 Correct 168 ms 8416 KB Output is correct
54 Correct 197 ms 8400 KB Output is correct
55 Correct 18 ms 2632 KB Output is correct
56 Correct 13 ms 2612 KB Output is correct
57 Correct 4 ms 1748 KB Output is correct
58 Correct 159 ms 8412 KB Output is correct
59 Correct 51 ms 3472 KB Output is correct
60 Correct 12 ms 2652 KB Output is correct
61 Correct 24 ms 3156 KB Output is correct
62 Correct 25 ms 3156 KB Output is correct
63 Correct 50 ms 4688 KB Output is correct
64 Correct 56 ms 4348 KB Output is correct
65 Correct 28 ms 3060 KB Output is correct
66 Correct 26 ms 3260 KB Output is correct
67 Correct 88 ms 5336 KB Output is correct
68 Correct 49 ms 4240 KB Output is correct
69 Correct 24 ms 3084 KB Output is correct
70 Correct 61 ms 4408 KB Output is correct
71 Correct 88 ms 5276 KB Output is correct
72 Correct 87 ms 5180 KB Output is correct
73 Correct 16 ms 2512 KB Output is correct
74 Correct 57 ms 4440 KB Output is correct
75 Correct 75 ms 5188 KB Output is correct
76 Correct 47 ms 3668 KB Output is correct
77 Correct 116 ms 6016 KB Output is correct
78 Correct 12 ms 2616 KB Output is correct
79 Correct 42 ms 3760 KB Output is correct
80 Correct 41 ms 3724 KB Output is correct
81 Correct 104 ms 6016 KB Output is correct
82 Correct 6 ms 1876 KB Output is correct
83 Correct 43 ms 3760 KB Output is correct
84 Correct 70 ms 5180 KB Output is correct
85 Correct 6 ms 1904 KB Output is correct
86 Correct 69 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 15 ms 2608 KB Output is correct
4 Correct 9 ms 2612 KB Output is correct
5 Correct 9 ms 2516 KB Output is correct
6 Correct 12 ms 2644 KB Output is correct
7 Correct 13 ms 2592 KB Output is correct
8 Correct 4 ms 1748 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 3 ms 1748 KB Output is correct
11 Correct 9 ms 2540 KB Output is correct
12 Correct 9 ms 2516 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 14 ms 2516 KB Output is correct
15 Correct 2 ms 1500 KB Output is correct
16 Correct 12 ms 2540 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 13 ms 2644 KB Output is correct
19 Correct 3 ms 1748 KB Output is correct
20 Correct 6 ms 2260 KB Output is correct
21 Correct 7 ms 2260 KB Output is correct
22 Correct 3 ms 1748 KB Output is correct
23 Correct 19 ms 2672 KB Output is correct
24 Correct 4 ms 1748 KB Output is correct
25 Correct 23 ms 2792 KB Output is correct
26 Correct 14 ms 2664 KB Output is correct
27 Correct 16 ms 2516 KB Output is correct
28 Correct 20 ms 2692 KB Output is correct
29 Correct 17 ms 2600 KB Output is correct
30 Correct 25 ms 2844 KB Output is correct
31 Correct 22 ms 2756 KB Output is correct
32 Correct 16 ms 2804 KB Output is correct
33 Correct 16 ms 2804 KB Output is correct
34 Correct 20 ms 2772 KB Output is correct
35 Correct 10 ms 2132 KB Output is correct
36 Correct 8 ms 2132 KB Output is correct
37 Correct 9 ms 2132 KB Output is correct
38 Correct 6 ms 1904 KB Output is correct
39 Correct 8 ms 1920 KB Output is correct
40 Correct 35 ms 3284 KB Output is correct
41 Correct 8 ms 1944 KB Output is correct
42 Correct 28 ms 3284 KB Output is correct
43 Correct 33 ms 3204 KB Output is correct
44 Correct 1 ms 1492 KB Output is correct
45 Correct 909 ms 26968 KB Output is correct
46 Correct 345 ms 16048 KB Output is correct
47 Correct 963 ms 27008 KB Output is correct
48 Correct 927 ms 26964 KB Output is correct
49 Correct 140 ms 12744 KB Output is correct
50 Correct 688 ms 33804 KB Output is correct
51 Correct 1004 ms 26956 KB Output is correct
52 Correct 229 ms 12748 KB Output is correct
53 Correct 152 ms 12724 KB Output is correct
54 Correct 19 ms 4052 KB Output is correct
55 Correct 669 ms 33812 KB Output is correct
56 Correct 81 ms 9116 KB Output is correct
57 Correct 173 ms 12748 KB Output is correct
58 Correct 283 ms 15944 KB Output is correct
59 Correct 139 ms 9036 KB Output is correct
60 Correct 96 ms 9108 KB Output is correct
61 Correct 292 ms 15864 KB Output is correct
62 Correct 183 ms 12444 KB Output is correct
63 Correct 481 ms 17864 KB Output is correct
64 Correct 102 ms 9044 KB Output is correct
65 Correct 608 ms 21512 KB Output is correct
66 Correct 179 ms 12504 KB Output is correct
67 Correct 549 ms 17840 KB Output is correct
68 Correct 669 ms 20552 KB Output is correct
69 Correct 594 ms 21600 KB Output is correct
70 Correct 227 ms 12440 KB Output is correct
71 Correct 574 ms 20608 KB Output is correct
72 Correct 407 ms 17224 KB Output is correct
73 Correct 764 ms 23684 KB Output is correct
74 Correct 224 ms 12628 KB Output is correct
75 Correct 174 ms 10268 KB Output is correct
76 Correct 341 ms 17280 KB Output is correct
77 Correct 631 ms 23704 KB Output is correct
78 Correct 255 ms 12604 KB Output is correct
79 Correct 205 ms 10300 KB Output is correct
80 Correct 96 ms 5956 KB Output is correct
81 Correct 315 ms 12600 KB Output is correct
82 Correct 517 ms 19356 KB Output is correct
83 Correct 77 ms 5924 KB Output is correct
84 Correct 469 ms 19356 KB Output is correct