Submission #129111

#TimeUsernameProblemLanguageResultExecution timeMemory
129111SamAndPolitical Development (BOI17_politicaldevelopment)C++17
100 / 100
161 ms9336 KiB
#include <bits/stdc++.h> using namespace std; const int N = 50004, K = 12; int n, k; vector<int> a[N]; bool c[N]; int q[N]; int f[1 << K]; int qq[1 << K]; void pre() { for (int x = 1; x < (1 << k); ++x) { int yq = 0; for (int i = 0; i < k; ++i) { if ((x & (1 << i))) { f[x] = i; ++yq; } } qq[x] = yq; } } vector<int> v; int xx[K]; bool dp[1 << K]; int stg() { memset(xx, 0, sizeof xx); for (int i = 0; i < v.size(); ++i) { for (int j = 0; j < v.size(); ++j) { if (binary_search(a[v[i]].begin(), a[v[i]].end(), v[j])) xx[i] |= (1 << j); } } memset(dp, false, sizeof dp); dp[0] = true; int ans = 0; for (int x = 1; x < (1 << v.size()); ++x) { int i = f[x]; int y = (x ^ (1 << i)); if (dp[y] && (xx[i] & y) == y) { dp[x] = true; ans = max(ans, qq[x]); } } return ans; } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { int s; scanf("%d", &s); while (s--) { int x; scanf("%d", &x); a[i].push_back(x); } } queue<int> s; for (int i = 0; i < n; ++i) { sort(a[i].begin(), a[i].end()); q[i] = a[i].size(); if (q[i] <= k) s.push(i); } pre(); int ans = 1; while (1) { v.clear(); int x; do { x = s.front(); s.pop(); if (s.empty()) { cout << ans << endl; return 0; } } while (c[x]); for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (c[h]) continue; v.push_back(h); --q[h]; if (q[h] <= k) s.push(h); } ans = max(ans, stg() + 1); c[x] = true; } return 0; }

Compilation message (stderr)

politicaldevelopment.cpp: In function 'int stg()':
politicaldevelopment.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
politicaldevelopment.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v.size(); ++j)
                         ~~^~~~~~~~~~
politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:97:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a[x].size(); ++i)
                         ~~^~~~~~~~~~~~~
politicaldevelopment.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
politicaldevelopment.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &s);
         ~~~~~^~~~~~~~~~
politicaldevelopment.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &x);
             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...