답안 #647884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647884 2022-10-04T11:42:29 Z mychecksedad Political Development (BOI17_politicaldevelopment) C++17
39 / 100
3000 ms 407400 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;


int n, k;
vector<int> g[N], path;
vector<bool> vis(N);
vector<bitset<50001>> is;
ll e[N];
void dfs(int v, int p){
    vis[v] = 1;
    path.pb(v);
    for(int u: g[v]){
        if(u != p){
            if(vis[u]){
                if(path[path.size() - 3] == u){
                    cout << 3;
                    exit(0);
                }
            }else{
                dfs(u, v);
            }
        }    
    }
    path.pop_back();
}

int mod(ll a){
    return ((a % MOD) + MOD) % MOD;
}

void solve(){
    cin >> n >> k;
    is.resize(n+1);
    for(int i = 0; i < n; ++i){
        int d; cin >> d;
        for(int j = 0; j < d; ++j){
            int x; cin >> x; g[i].pb(x); is[i][x] = 1;
        }
    }
    if(k <= 2){
        for(int i = 0; i < n; ++i){
            if(g[i].size()){
                cout << 2;
                return;
            }
        }
        cout << 1;
        return;
    }
    if(k <= 3){
        for(int i = 0; i < n; ++i) if(!vis[i]) dfs(i, i);
        for(int i = 0; i < n; ++i){
            if(g[i].size()){
                cout << 2;
                return;
            }
        }
        cout << 1;
        return;
    }

    e[0] = 1;
    for(int i = 1; i < N; ++i) e[i] = (e[i - 1] * 3) % MOD;

    vector<vector<int>> v;
    for(int i = 0; i < n; ++i) v.pb({i});
    for(int j = 2; j <= k; ++j){
        bitset<50001> out, in;
        vector<vector<int>> t;
        map<ll, bool> m;

        if(n <= 5000){
            for(auto &u: v){
                ll h = 0;
                for(int x: u) in[x] = 1, h += e[x];
                h = mod(h);
                for(int i = 0; i < n; ++i){
                    if(!in[i]){
                        bool ok = 1;
                        for(int d: u){
                            if(!is[d][i]){
                                ok = 0;
                                break;
                            }
                        }
                        if(ok){
                            h = mod(h + e[i]);
                            if(!m[h]){
                                m[h] = 1;
                                u.pb(i);
                                t.pb(u);
                                u.pop_back();
                            }
                            h = mod(h - e[i]);
                        }
                    }
                }
                for(int x: u) in[x] = 0;
            }
        }else{
            for(auto &u: v){
                for(int x: u) in[x] = 1;
                vector<int> extend;
                for(int x: u){
                    for(int e: g[x]){
                        if(!out[e] && !in[e]){
                            out[e] = 1;
                            extend.pb(e);
                        }
                    }
                }
                for(int x: extend){
                    out[x] = 0;
                    bool ok = 1;
                    for(int p: u){
                        if(!is[p][x]){
                            ok = 0;
                            break;
                        }
                    }
                    if(ok){
                        u.pb(x);
                        t.pb(u);
                        u.pop_back();
                    }
                }
                for(int x: u) in[x] = 0;
            }
        }
        if(t.size() == 0){
            cout << j - 1;
            return;
        }
        v = t;
    }
    cout << k;
}   





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:160:16: warning: unused variable 'aa' [-Wunused-variable]
  160 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 15 ms 23892 KB Output is correct
3 Correct 26 ms 54616 KB Output is correct
4 Correct 26 ms 54708 KB Output is correct
5 Correct 29 ms 54688 KB Output is correct
6 Correct 26 ms 54696 KB Output is correct
7 Correct 26 ms 54664 KB Output is correct
8 Correct 24 ms 54484 KB Output is correct
9 Correct 14 ms 23900 KB Output is correct
10 Correct 24 ms 54528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 15 ms 23892 KB Output is correct
3 Correct 26 ms 54616 KB Output is correct
4 Correct 26 ms 54708 KB Output is correct
5 Correct 29 ms 54688 KB Output is correct
6 Correct 26 ms 54696 KB Output is correct
7 Correct 26 ms 54664 KB Output is correct
8 Correct 24 ms 54484 KB Output is correct
9 Correct 14 ms 23900 KB Output is correct
10 Correct 24 ms 54528 KB Output is correct
11 Correct 25 ms 54712 KB Output is correct
12 Correct 25 ms 54676 KB Output is correct
13 Correct 12 ms 23908 KB Output is correct
14 Correct 24 ms 54620 KB Output is correct
15 Correct 12 ms 23888 KB Output is correct
16 Correct 26 ms 54740 KB Output is correct
17 Correct 12 ms 23892 KB Output is correct
18 Correct 25 ms 54732 KB Output is correct
19 Correct 24 ms 54484 KB Output is correct
20 Correct 25 ms 54604 KB Output is correct
21 Correct 25 ms 54652 KB Output is correct
22 Correct 24 ms 54492 KB Output is correct
23 Correct 26 ms 54744 KB Output is correct
24 Correct 24 ms 54444 KB Output is correct
25 Correct 28 ms 54740 KB Output is correct
26 Correct 25 ms 54796 KB Output is correct
27 Correct 26 ms 54996 KB Output is correct
28 Correct 27 ms 54808 KB Output is correct
29 Correct 26 ms 54996 KB Output is correct
30 Correct 28 ms 54636 KB Output is correct
31 Correct 26 ms 54868 KB Output is correct
32 Correct 26 ms 54740 KB Output is correct
33 Correct 28 ms 54868 KB Output is correct
34 Correct 28 ms 54828 KB Output is correct
35 Correct 21 ms 39420 KB Output is correct
36 Correct 20 ms 39444 KB Output is correct
37 Correct 20 ms 39424 KB Output is correct
38 Correct 16 ms 31572 KB Output is correct
39 Correct 16 ms 31572 KB Output is correct
40 Correct 27 ms 54644 KB Output is correct
41 Correct 15 ms 31560 KB Output is correct
42 Correct 28 ms 54720 KB Output is correct
43 Correct 28 ms 54864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 62676 KB Output is correct
2 Correct 21 ms 31848 KB Output is correct
3 Correct 21 ms 31852 KB Output is correct
4 Correct 22 ms 31820 KB Output is correct
5 Correct 20 ms 31868 KB Output is correct
6 Correct 20 ms 31828 KB Output is correct
7 Correct 21 ms 31856 KB Output is correct
8 Correct 20 ms 31816 KB Output is correct
9 Correct 20 ms 31876 KB Output is correct
10 Correct 20 ms 31900 KB Output is correct
11 Correct 624 ms 393772 KB Output is correct
12 Correct 20 ms 31828 KB Output is correct
13 Correct 1222 ms 407300 KB Output is correct
14 Correct 20 ms 31828 KB Output is correct
15 Correct 623 ms 393900 KB Output is correct
16 Correct 707 ms 393748 KB Output is correct
17 Correct 1212 ms 407400 KB Output is correct
18 Correct 728 ms 393808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 15 ms 23892 KB Output is correct
3 Correct 26 ms 54616 KB Output is correct
4 Correct 26 ms 54708 KB Output is correct
5 Correct 29 ms 54688 KB Output is correct
6 Correct 26 ms 54696 KB Output is correct
7 Correct 26 ms 54664 KB Output is correct
8 Correct 24 ms 54484 KB Output is correct
9 Correct 14 ms 23900 KB Output is correct
10 Correct 24 ms 54528 KB Output is correct
11 Correct 25 ms 54712 KB Output is correct
12 Correct 25 ms 54676 KB Output is correct
13 Correct 12 ms 23908 KB Output is correct
14 Correct 24 ms 54620 KB Output is correct
15 Correct 12 ms 23888 KB Output is correct
16 Correct 26 ms 54740 KB Output is correct
17 Correct 12 ms 23892 KB Output is correct
18 Correct 25 ms 54732 KB Output is correct
19 Correct 24 ms 54484 KB Output is correct
20 Correct 25 ms 54604 KB Output is correct
21 Correct 25 ms 54652 KB Output is correct
22 Correct 24 ms 54492 KB Output is correct
23 Correct 26 ms 54744 KB Output is correct
24 Correct 24 ms 54444 KB Output is correct
25 Correct 28 ms 54740 KB Output is correct
26 Correct 25 ms 54796 KB Output is correct
27 Correct 26 ms 54996 KB Output is correct
28 Correct 27 ms 54808 KB Output is correct
29 Correct 26 ms 54996 KB Output is correct
30 Correct 28 ms 54636 KB Output is correct
31 Correct 26 ms 54868 KB Output is correct
32 Correct 26 ms 54740 KB Output is correct
33 Correct 28 ms 54868 KB Output is correct
34 Correct 28 ms 54828 KB Output is correct
35 Correct 21 ms 39420 KB Output is correct
36 Correct 20 ms 39444 KB Output is correct
37 Correct 20 ms 39424 KB Output is correct
38 Correct 16 ms 31572 KB Output is correct
39 Correct 16 ms 31572 KB Output is correct
40 Correct 27 ms 54644 KB Output is correct
41 Correct 15 ms 31560 KB Output is correct
42 Correct 28 ms 54720 KB Output is correct
43 Correct 28 ms 54864 KB Output is correct
44 Execution timed out 3074 ms 79496 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23892 KB Output is correct
2 Correct 15 ms 23892 KB Output is correct
3 Correct 26 ms 54616 KB Output is correct
4 Correct 26 ms 54708 KB Output is correct
5 Correct 29 ms 54688 KB Output is correct
6 Correct 26 ms 54696 KB Output is correct
7 Correct 26 ms 54664 KB Output is correct
8 Correct 24 ms 54484 KB Output is correct
9 Correct 14 ms 23900 KB Output is correct
10 Correct 24 ms 54528 KB Output is correct
11 Correct 25 ms 54712 KB Output is correct
12 Correct 25 ms 54676 KB Output is correct
13 Correct 12 ms 23908 KB Output is correct
14 Correct 24 ms 54620 KB Output is correct
15 Correct 12 ms 23888 KB Output is correct
16 Correct 26 ms 54740 KB Output is correct
17 Correct 12 ms 23892 KB Output is correct
18 Correct 25 ms 54732 KB Output is correct
19 Correct 24 ms 54484 KB Output is correct
20 Correct 25 ms 54604 KB Output is correct
21 Correct 25 ms 54652 KB Output is correct
22 Correct 24 ms 54492 KB Output is correct
23 Correct 26 ms 54744 KB Output is correct
24 Correct 24 ms 54444 KB Output is correct
25 Correct 28 ms 54740 KB Output is correct
26 Correct 25 ms 54796 KB Output is correct
27 Correct 26 ms 54996 KB Output is correct
28 Correct 27 ms 54808 KB Output is correct
29 Correct 26 ms 54996 KB Output is correct
30 Correct 28 ms 54636 KB Output is correct
31 Correct 26 ms 54868 KB Output is correct
32 Correct 26 ms 54740 KB Output is correct
33 Correct 28 ms 54868 KB Output is correct
34 Correct 28 ms 54828 KB Output is correct
35 Correct 21 ms 39420 KB Output is correct
36 Correct 20 ms 39444 KB Output is correct
37 Correct 20 ms 39424 KB Output is correct
38 Correct 16 ms 31572 KB Output is correct
39 Correct 16 ms 31572 KB Output is correct
40 Correct 27 ms 54644 KB Output is correct
41 Correct 15 ms 31560 KB Output is correct
42 Correct 28 ms 54720 KB Output is correct
43 Correct 28 ms 54864 KB Output is correct
44 Correct 20 ms 31828 KB Output is correct
45 Correct 478 ms 375764 KB Output is correct
46 Execution timed out 3088 ms 358672 KB Time limit exceeded
47 Halted 0 ms 0 KB -