# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
137904 | onjo0127 | Bitwise (BOI06_bitwise) | C++11 | 2 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>
using namespace std;
int N, P;
long long A[109], B[109];
vector<int> S[109];
int main() {
scanf("%d%d",&N,&P);
for(int i=1, j=1; i<=P; i++) {
int foo; scanf("%d",&foo);
while(foo--) S[i].push_back(j++);
}
for(int i=1; i<=N; i++) scanf("%lld%lld",&A[i],&B[i]);
long long ans = 0;
for(int i=31; i>=0; i--) {
bool f = 1;
vector<int> T;
for(int j=1; j<=P; j++) {
bool l = 0;
int mx = -1, mxi = -1;
for(auto& it: S[j]) {
if(A[it] & (1LL << i)) l = 1;
else {
long long tmp = A[it] + (1LL << i);
for(int k=i-1; k>=0; k--) if(tmp & (1LL << k)) tmp -= (1LL << k);
if(mx < B[it] - tmp) mx = B[it] - tmp, mxi = it;
}
}
if(l) mxi = -1;
else {
if(mxi != -1) {
l = 1;
T.push_back(mxi);
}
else l = 0;
}
f &= l;
}
if(f) {
ans += (1LL << i);
for(auto& it: T) {
long long tmp = A[it] + (1LL << i);
for(int k=i-1; k>=0; k--) if(tmp & (1LL << k)) tmp -= (1LL << k);
A[it] = tmp, B[it] = min(tmp + (1LL << i) - 1, B[it]);
}
}
}
printf("%lld", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |