Submission #1104110

#TimeUsernameProblemLanguageResultExecution timeMemory
1104110Kirill22Bitwise (BOI06_bitwise)C++17
100 / 100
1 ms508 KiB
#include "bits/stdc++.h" using namespace std; void rem(long long& x, int j) { if (x >> j & 1ll) { x -= (1ll << j); } } void solve() { int n, p; cin >> n >> p; vector<int> sz(p); for (int i = 0; i < p; i++) { cin >> sz[i]; } vector<vector<pair<long long, long long>>> groups(p); for (int i = 0; i < p; i++) { groups[i].resize(sz[i]); for (auto& [x, y] : groups[i]) { cin >> x >> y; } } auto check2 = [&] (vector<pair<long long, long long>> a, long long x) -> bool { for (auto& [l, r] : a) { for (int j = 32; j >= 0; j--) { if ((l >> j & 1ll) == (r >> j & 1ll)) { if (l >> j & 1ll) { rem(x, j); rem(l, j); rem(r, j); } } else { break; } } } for (auto& [l, r] : a) { while (r) { int j = 0; while ((1ll << (j + 1)) <= r) { j++; } if (x >> j & 1ll) { rem(r, j); rem(x, j); } else { for (int j2 = 0; j2 < j; j2++) { rem(x, j2); } break; } } } return x == 0; }; auto check = [&] (long long x) { bool ok = true; for (auto g : groups) { ok &= check2(g, x); } return ok; }; long long ans = 0; for (int j = 32; j >= 0; j--) { if (check(ans + (1ll << j))) { ans += (1ll << j); } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...