Submission #697701

#TimeUsernameProblemLanguageResultExecution timeMemory
697701finn__Bitwise (BOI06_bitwise)C++17
100 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; // Whether x can be built from elements in z. bool is_possible(vector<pair<unsigned, unsigned>> z, unsigned x) { if (!x) return 1; // Incorporate all "fixed" bits of elements in z, as they will always be // present. Must be taken out since not all bits afterwards are arbitrarily // variable. for (auto &[i, j] : z) while (i && __builtin_clz(i) == __builtin_clz(j)) { unsigned const b = 31 - __builtin_clz(i); i ^= 1 << b, j ^= 1 << b; if (x & (1 << b)) x ^= 1 << b; } if (!x) return 1; // See if one element covers all remaining bits of x. for (auto const &[i, j] : z) if (j && __builtin_clz(j) < __builtin_clz(x)) return 1; // See if two elements cover all remaining bits of x. unsigned c = 0; for (auto const &[i, j] : z) if (j) c += __builtin_clz(j) == __builtin_clz(x); if (c >= 2) return 1; // Select the unique (=> branching factor 1) element to cover the missing // bit and solve for the remaining bits. for (auto &[i, j] : z) if (j && __builtin_clz(j) == __builtin_clz(x)) { unsigned const b = 31 - __builtin_clz(j); i = 0, j ^= 1 << b, x ^= 1 << b; return is_possible(z, x); } return 0; } int main() { size_t n, p; cin >> n >> p; vector<vector<pair<unsigned, unsigned>>> y(p); for (size_t i = 0; i < p; i++) { size_t k; cin >> k; y[i] = vector<pair<unsigned, unsigned>>(k); } for (size_t i = 0; i < p; i++) for (auto &[a, b] : y[i]) cin >> a >> b; unsigned x = 0; for (unsigned b = 30; b < 31U; b--) { x ^= 1 << b; for (auto const &z : y) if (!is_possible(z, x)) { x ^= 1 << b; break; } } cout << x << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...