답안 #589350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589350 2022-07-04T13:42:06 Z MohammadAghil Political Development (BOI17_politicaldevelopment) C++17
100 / 100
231 ms 9828 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<ll, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      freopen("in.in", "r", stdin);
     //      freopen("out.out", "w", stdout);
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e4 + 5, maxk = 11, lg = 35, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

vector<int> adj[maxn];
vector<int> mask[maxk][maxk];
int cnt[maxn];

bool chk(int x, vector<int> cand){
     int n = sz(cand);
     vector<int> adj(n);
     rep(i,0,n) {
          adj[i] ^= 1<<i;
          rep(j,0,i){
               auto it = lower_bound(all(::adj[cand[i]]), cand[j]);
               if(it != end(::adj[i]) && *it == cand[j]) adj[i] ^= 1<<j, adj[j] ^= 1<<i;
          }
     }
     for(int m: mask[n][x]){
          bool ok = true;
          rep(i,0,n) if((m>>i&1) && (adj[i]&m) != m) {
               ok = false;
               break;
          } 
          if(ok) return true;
     }
     return false;
}

int main(){ IOS();
     int n, k, ans = 1; cin >> n >> k;
     set<pp> s;
     rep(i,0,n){
          int d; cin >> d;
          s.insert({cnt[i] = d, i});
          adj[i].resize(d);
          rep(j,0,d) cin >> adj[i][j];
          sort(all(adj[i]));
     }
     rep(i,0,k+1){
          rep(j,0,1<<i) mask[i][__builtin_popcount(j)].pb(j);
     }
     while(sz(s)){
          int r = s.begin()->ss;
          s.erase(begin(s)), cnt[r] = -1;
          vector<int> ad{r};
          for(int c: adj[r]) if(cnt[c] > 0){
               ad.pb(c);
               s.erase(pp(cnt[c], c));
               s.insert({--cnt[c], c});
          }
          // er(r);
          // for(int c: ad) cerr << c << ' '; cerr << endl;
          while(ans < sz(ad) && chk(ans+1, ad)) ans++;
     }
     cout << ans << '\n';
     return 0;  
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 5 ms 2004 KB Output is correct
4 Correct 4 ms 2084 KB Output is correct
5 Correct 4 ms 2004 KB Output is correct
6 Correct 5 ms 2020 KB Output is correct
7 Correct 4 ms 2004 KB Output is correct
8 Correct 2 ms 1768 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 5 ms 2004 KB Output is correct
4 Correct 4 ms 2084 KB Output is correct
5 Correct 4 ms 2004 KB Output is correct
6 Correct 5 ms 2020 KB Output is correct
7 Correct 4 ms 2004 KB Output is correct
8 Correct 2 ms 1768 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 4 ms 2004 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 4 ms 2032 KB Output is correct
15 Correct 1 ms 1508 KB Output is correct
16 Correct 6 ms 2036 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 5 ms 2024 KB Output is correct
19 Correct 2 ms 1748 KB Output is correct
20 Correct 3 ms 2004 KB Output is correct
21 Correct 4 ms 2004 KB Output is correct
22 Correct 2 ms 1772 KB Output is correct
23 Correct 6 ms 2068 KB Output is correct
24 Correct 2 ms 1748 KB Output is correct
25 Correct 6 ms 2036 KB Output is correct
26 Correct 5 ms 2004 KB Output is correct
27 Correct 5 ms 2004 KB Output is correct
28 Correct 5 ms 2056 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 7 ms 2004 KB Output is correct
31 Correct 6 ms 2004 KB Output is correct
32 Correct 6 ms 2032 KB Output is correct
33 Correct 6 ms 2064 KB Output is correct
34 Correct 6 ms 1964 KB Output is correct
35 Correct 3 ms 1748 KB Output is correct
36 Correct 3 ms 1732 KB Output is correct
37 Correct 3 ms 1780 KB Output is correct
38 Correct 3 ms 1648 KB Output is correct
39 Correct 3 ms 1644 KB Output is correct
40 Correct 7 ms 2116 KB Output is correct
41 Correct 3 ms 1644 KB Output is correct
42 Correct 7 ms 2004 KB Output is correct
43 Correct 8 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1504 KB Output is correct
5 Correct 1 ms 1504 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 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 230 ms 9740 KB Output is correct
12 Correct 1 ms 1392 KB Output is correct
13 Correct 214 ms 9828 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 214 ms 9824 KB Output is correct
16 Correct 223 ms 9804 KB Output is correct
17 Correct 214 ms 9824 KB Output is correct
18 Correct 231 ms 9772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 5 ms 2004 KB Output is correct
4 Correct 4 ms 2084 KB Output is correct
5 Correct 4 ms 2004 KB Output is correct
6 Correct 5 ms 2020 KB Output is correct
7 Correct 4 ms 2004 KB Output is correct
8 Correct 2 ms 1768 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 4 ms 2004 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 4 ms 2032 KB Output is correct
15 Correct 1 ms 1508 KB Output is correct
16 Correct 6 ms 2036 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 5 ms 2024 KB Output is correct
19 Correct 2 ms 1748 KB Output is correct
20 Correct 3 ms 2004 KB Output is correct
21 Correct 4 ms 2004 KB Output is correct
22 Correct 2 ms 1772 KB Output is correct
23 Correct 6 ms 2068 KB Output is correct
24 Correct 2 ms 1748 KB Output is correct
25 Correct 6 ms 2036 KB Output is correct
26 Correct 5 ms 2004 KB Output is correct
27 Correct 5 ms 2004 KB Output is correct
28 Correct 5 ms 2056 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 7 ms 2004 KB Output is correct
31 Correct 6 ms 2004 KB Output is correct
32 Correct 6 ms 2032 KB Output is correct
33 Correct 6 ms 2064 KB Output is correct
34 Correct 6 ms 1964 KB Output is correct
35 Correct 3 ms 1748 KB Output is correct
36 Correct 3 ms 1732 KB Output is correct
37 Correct 3 ms 1780 KB Output is correct
38 Correct 3 ms 1648 KB Output is correct
39 Correct 3 ms 1644 KB Output is correct
40 Correct 7 ms 2116 KB Output is correct
41 Correct 3 ms 1644 KB Output is correct
42 Correct 7 ms 2004 KB Output is correct
43 Correct 8 ms 2040 KB Output is correct
44 Correct 9 ms 2260 KB Output is correct
45 Correct 1 ms 1492 KB Output is correct
46 Correct 7 ms 2004 KB Output is correct
47 Correct 14 ms 2260 KB Output is correct
48 Correct 8 ms 2004 KB Output is correct
49 Correct 15 ms 2252 KB Output is correct
50 Correct 14 ms 2260 KB Output is correct
51 Correct 34 ms 2612 KB Output is correct
52 Correct 6 ms 2048 KB Output is correct
53 Correct 29 ms 2692 KB Output is correct
54 Correct 40 ms 2644 KB Output is correct
55 Correct 5 ms 2028 KB Output is correct
56 Correct 4 ms 2004 KB Output is correct
57 Correct 2 ms 1748 KB Output is correct
58 Correct 26 ms 2644 KB Output is correct
59 Correct 6 ms 2004 KB Output is correct
60 Correct 5 ms 2004 KB Output is correct
61 Correct 6 ms 2004 KB Output is correct
62 Correct 7 ms 2100 KB Output is correct
63 Correct 10 ms 2284 KB Output is correct
64 Correct 8 ms 2260 KB Output is correct
65 Correct 8 ms 2000 KB Output is correct
66 Correct 7 ms 2108 KB Output is correct
67 Correct 16 ms 2316 KB Output is correct
68 Correct 8 ms 2160 KB Output is correct
69 Correct 7 ms 2024 KB Output is correct
70 Correct 12 ms 2132 KB Output is correct
71 Correct 16 ms 2260 KB Output is correct
72 Correct 15 ms 2260 KB Output is correct
73 Correct 5 ms 2004 KB Output is correct
74 Correct 12 ms 2132 KB Output is correct
75 Correct 16 ms 2340 KB Output is correct
76 Correct 10 ms 2132 KB Output is correct
77 Correct 21 ms 2388 KB Output is correct
78 Correct 6 ms 2004 KB Output is correct
79 Correct 10 ms 1888 KB Output is correct
80 Correct 9 ms 2032 KB Output is correct
81 Correct 20 ms 2432 KB Output is correct
82 Correct 3 ms 1620 KB Output is correct
83 Correct 10 ms 1876 KB Output is correct
84 Correct 16 ms 2260 KB Output is correct
85 Correct 3 ms 1644 KB Output is correct
86 Correct 13 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1508 KB Output is correct
3 Correct 5 ms 2004 KB Output is correct
4 Correct 4 ms 2084 KB Output is correct
5 Correct 4 ms 2004 KB Output is correct
6 Correct 5 ms 2020 KB Output is correct
7 Correct 4 ms 2004 KB Output is correct
8 Correct 2 ms 1768 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 2 ms 1748 KB Output is correct
11 Correct 4 ms 2004 KB Output is correct
12 Correct 6 ms 2004 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 4 ms 2032 KB Output is correct
15 Correct 1 ms 1508 KB Output is correct
16 Correct 6 ms 2036 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 5 ms 2024 KB Output is correct
19 Correct 2 ms 1748 KB Output is correct
20 Correct 3 ms 2004 KB Output is correct
21 Correct 4 ms 2004 KB Output is correct
22 Correct 2 ms 1772 KB Output is correct
23 Correct 6 ms 2068 KB Output is correct
24 Correct 2 ms 1748 KB Output is correct
25 Correct 6 ms 2036 KB Output is correct
26 Correct 5 ms 2004 KB Output is correct
27 Correct 5 ms 2004 KB Output is correct
28 Correct 5 ms 2056 KB Output is correct
29 Correct 4 ms 2004 KB Output is correct
30 Correct 7 ms 2004 KB Output is correct
31 Correct 6 ms 2004 KB Output is correct
32 Correct 6 ms 2032 KB Output is correct
33 Correct 6 ms 2064 KB Output is correct
34 Correct 6 ms 1964 KB Output is correct
35 Correct 3 ms 1748 KB Output is correct
36 Correct 3 ms 1732 KB Output is correct
37 Correct 3 ms 1780 KB Output is correct
38 Correct 3 ms 1648 KB Output is correct
39 Correct 3 ms 1644 KB Output is correct
40 Correct 7 ms 2116 KB Output is correct
41 Correct 3 ms 1644 KB Output is correct
42 Correct 7 ms 2004 KB Output is correct
43 Correct 8 ms 2040 KB Output is correct
44 Correct 1 ms 1492 KB Output is correct
45 Correct 146 ms 8544 KB Output is correct
46 Correct 55 ms 7316 KB Output is correct
47 Correct 167 ms 8436 KB Output is correct
48 Correct 134 ms 8540 KB Output is correct
49 Correct 43 ms 7224 KB Output is correct
50 Correct 137 ms 9536 KB Output is correct
51 Correct 137 ms 8496 KB Output is correct
52 Correct 41 ms 7252 KB Output is correct
53 Correct 52 ms 7176 KB Output is correct
54 Correct 15 ms 4844 KB Output is correct
55 Correct 146 ms 9532 KB Output is correct
56 Correct 34 ms 6896 KB Output is correct
57 Correct 39 ms 7144 KB Output is correct
58 Correct 48 ms 7308 KB Output is correct
59 Correct 32 ms 6760 KB Output is correct
60 Correct 30 ms 6644 KB Output is correct
61 Correct 50 ms 7232 KB Output is correct
62 Correct 52 ms 7028 KB Output is correct
63 Correct 76 ms 7520 KB Output is correct
64 Correct 29 ms 6764 KB Output is correct
65 Correct 93 ms 7832 KB Output is correct
66 Correct 43 ms 6988 KB Output is correct
67 Correct 83 ms 7408 KB Output is correct
68 Correct 97 ms 7780 KB Output is correct
69 Correct 95 ms 7812 KB Output is correct
70 Correct 45 ms 6996 KB Output is correct
71 Correct 92 ms 7724 KB Output is correct
72 Correct 71 ms 7564 KB Output is correct
73 Correct 117 ms 8008 KB Output is correct
74 Correct 47 ms 7052 KB Output is correct
75 Correct 42 ms 4524 KB Output is correct
76 Correct 68 ms 7500 KB Output is correct
77 Correct 145 ms 8140 KB Output is correct
78 Correct 55 ms 4740 KB Output is correct
79 Correct 48 ms 4460 KB Output is correct
80 Correct 19 ms 3072 KB Output is correct
81 Correct 51 ms 4692 KB Output is correct
82 Correct 89 ms 7528 KB Output is correct
83 Correct 19 ms 3052 KB Output is correct
84 Correct 107 ms 7624 KB Output is correct