Submission #1104110

# Submission time Handle Problem Language Result Execution time Memory
1104110 2024-10-22T20:08:34 Z Kirill22 Bitwise (BOI06_bitwise) C++17
100 / 100
1 ms 508 KB
#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 time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 504 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct