# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951225 | PM1 | Bitwise (BOI06_bitwise) | C++17 | 1 ms | 348 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;
#define fr first
#define sc second
const int mxn=105;
int n,p,cnt[mxn],ans=0;
vector<pair<int,int>>v[mxn];
int main(){
cin>>n>>p;
for(int i=1;i<=p;i++)
cin>>cnt[i];
for(int i=1;i<=p;i++){
while(cnt[i]--){
int a,b;
cin>>a>>b;
v[i].push_back({a,b});
}
}
for(int k=30;k>=0;k--){
bool t=1;
for(int i=1;i<=p;i++){
int g=0,gg=0;
for(auto j:v[i]){
//cout<<j.fr<<" "<<j.sc<<'\n';
if(j.fr>=(1<<k) && j.sc>=(1<<k))g++;
else if(j.sc>=(1<<k))gg++;
}
if(g+gg==0){
t=0;
break;
}
}
if(!t)
continue;
else{
ans+=(1<<k);
for(int i=1;i<=p;i++){
int g=0,gg=0;
for(auto j:v[i]){
if(j.fr>=(1<<k) && j.sc>=(1<<k))g++;
else if(j.sc>=(1<<k))gg++;
}
if(g){
for(int j=0;j<v[i].size();j++){
auto y=v[i][j];
if(y.fr>=(1<<k) && y.sc>=(1<<k)){
v[i][j].fr-=(1<<k);
v[i][j].sc-=(1<<k);
}
}
}
else{
for(int j=0;j<v[i].size();j++){
auto y=v[i][j];
if(y.fr<(1<<k) && y.sc>=(1<<k)){
v[i][j].fr-=(1<<k);
v[i][j].sc-=(1<<k);
break;
}
}
}
}
}
}
cout<<ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |