# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198906 | dolphingarlic | Bitwise (BOI06_bitwise) | C++14 | 7 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
int n, p, sz[101], lo[101], hi[101];
bool check(int pos) {
for (int i = 0, idx = 0; idx < p; i += sz[idx], idx++) {
bool possible = false;
FOR(j, i, i + sz[idx]) if (hi[j] & (1 << pos)) possible = true;
if (!possible) {
FOR(j, 0, n) {
if ((hi[j] & (1 << pos)) && !(lo[j] & (1 << pos))) {
FOR(k, 0, pos) hi[j] |= (1 << k);
}
}
return false;
}
}
for (int i = 0, idx = 0; idx < p; i += sz[idx], idx++) {
bool assigned = false;
FOR(j, i, i + sz[idx]) if ((hi[j] & (1 << pos)) && (lo[j] & (1 << pos))) assigned = true;
FOR(j, i, i + sz[idx]) {
if ((hi[j] & (1 << pos)) && !(lo[j] & (1 << pos))) {
if (!assigned) {
assigned = true;
lo[j] = 0;
} else FOR(k, 0, pos) hi[j] |= (1 << k);
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> p;
FOR(i, 0, p) cin >> sz[i];
FOR(i, 0, n) cin >> lo[i] >> hi[i];
int ans = 0;
for (int i = 31; ~i; i--) if (check(i)) ans |= 1 << i;
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |