QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227439 | #7560. Computer Network | salvator_noster# | WA | 1ms | 8040kb | C++14 | 911b | 2023-10-27 15:55:23 | 2023-10-27 15:55:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int M=1e6+10;
int a[M],b[M],c[M];
int main(){
int n;
scanf("%d",&n);
int ans=1e9+1;
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;++i){
scanf("%d",&b[i]);
}
for(int k=0;k<=30;++k){
int t=1e9+1;
for(int i=1;i<=n;++i){
c[i]=b[i]-(a[i]>>k);
t=min(c[i],t);
}
if(t<0)continue;
int res=k+t,fl=1;
for(int i=1;i<=n;++i){
c[i]-=t;
if(c[i]>1)fl=0;
}
if(!fl)continue;
// cout<<k<<" "<<t<<endl;
// for(int i=1;i<=n;++i)printf("%d ",c[i]);
// puts("");
int l=0,r=(1<<k)-1;
for(int i=1;i<=n;++i){
t=((1<<k)-1)^(((1<<k)-1)&a[i]);
if(c[i])l=max(l,t+1);
else r=min(r,t);
}
if(l>r)continue;
for(int i=k-1;i>=0;i--){
if(((l>>i)&1)^((r>>i)&1)){
res++;
break;
}
if(l>>i&1)res++;
}
ans=min(ans,res);
}
printf("%d",ans>1e9?-1:ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8040kb
input:
5 1 2 3 4 5 6 6 6 6 7
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7892kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7828kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 1ms
memory: 8040kb
input:
1 0 28
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 7956kb
input:
1 249912 43
output:
27
result:
wrong answer 1st numbers differ - expected: '26', found: '27'