Submission #1035290

#TimeUsernameProblemLanguageResultExecution timeMemory
1035290vjudge1Political Development (BOI17_politicaldevelopment)C++17
0 / 100
34 ms24948 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e4; mt19937 rng(time(nullptr) + 69); int n, k, cnt[N]; vector<int> rem, adj[2][N]; bitset<N> r, bt[N], curr, prv; bool solve(int tot, int x, int y) { if (curr.count() < tot || n-1 - y < x) return 0; else if (!x) return 1; // tengo que pillar x mas, mayores que y, tengo curr odiados vector<int> temp; int sz = rem.size(); for (int i = sz-1; i >= 0; i--) { if (rem[i] <= y) break; temp.push_back(rem[i]); } shuffle(temp.begin(), temp.end(), rng); sz = temp.size(); for (int i = 0; i < sz; i++) { prv = curr; curr &= bt[temp[i]]; if (solve(tot, x-1, temp[i])) return 1; swap(curr, prv); } return 0; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; memset(cnt, 0, sizeof(cnt)); rem.resize(n); for (int i = 0; i < n; i++) { rem[i] = i; int x; cin >> x; bt[i][i] = 1; cnt[i]++; adj[0][i].push_back(i); adj[1][i].push_back(i); for (int j = 0; j < x; j++) { int y; cin >> y; bt[i][y] = 1; cnt[y]++; adj[0][i].push_back(y); adj[1][y].push_back(i); } } int ans = 0; for (int i = 1; i <= k; i++) { for (int& j : rem) curr[j] = 1; if (!solve(i, i, -1)) break; ans = i; // limpiar while (1) { int sz = rem.size(); vector<int> nw; bool ch = 0; for (int j = 0; j < sz; j++) { int c = 0; for (int& k : adj[0][rem[j]]) { if (cnt[k] >= i) c++; } if (c >= i) { nw.push_back(rem[j]); continue; } ch = 1; for (int& k : adj[0][rem[j]]) { cnt[k]--; } } swap(nw, rem); if (!ch) break; } } cout << ans << "\n"; }

Compilation message (stderr)

politicaldevelopment.cpp: In function 'bool solve(int, int, int)':
politicaldevelopment.cpp:13:20: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |   if (curr.count() < tot || n-1 - y < x) return 0;
      |       ~~~~~~~~~~~~~^~~~~
#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...