QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226830 | #7560. Computer Network | ucup-team2307# | WA | 1ms | 5624kb | C++20 | 1.3kb | 2023-10-26 16:56:37 | 2023-10-26 16:56:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int N=1e6+100,INF=1e10;
int a[N],b[N];
int min_bits(int l,int r)
{
if(l==r)
return __builtin_popcount(l);
int x=l^r;
int i=63-__builtin_clzll(x);
int m=r>>i;
return __builtin_popcount(m);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
int ans=INF;
for(int div=0;div<=30;div++)
{
int l=0,r=INF;
for(int i=1;i<=n;i++)
{
l=max(l,b[i]-a[i]);
r=min(r,b[i]-a[i]+(1<<div)-1);
}
// cout<<div<<":\n";
// for(int i=1;i<=n;i++)
// cout<<a[i]<<" ";
// cout<<"\n";
// for(int i=1;i<=n;i++)
// cout<<b[i]<<" ";
// cout<<"\n";
// cout<<"-> "<<l<<".."<<r<<"\n";
for(int i=1;i<=n;i++)
b[i]*=2;
if(l>r)
continue;
int l1=l>>div;
int l2=l&((1<<div)-1);
int r1=r>>div;
int r2=r&((1<<div)-1);
if(l1==r1)
ans=min(ans,div+l1+min_bits(l2,r2));
else
ans=min(ans,div+r1);
}
cout<<(ans==INF?-1:ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5416kb
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: 5460kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5472kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5584kb
input:
1 0 28
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5464kb
input:
1 249912 43
output:
26
result:
ok 1 number(s): "26"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5584kb
input:
2 52522336 155670 52532336 165670
output:
10000
result:
ok 1 number(s): "10000"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5456kb
input:
2 141839218 538313890 17731054 67290388
output:
1155
result:
ok 1 number(s): "1155"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
2 678834913 571995689 84855772 71500869
output:
1411
result:
ok 1 number(s): "1411"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5448kb
input:
10 66 0 65 10 40 1 44 29 13 15 84 18 83 28 58 19 62 47 31 33
output:
18
result:
ok 1 number(s): "18"
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 5468kb
input:
10 0 74752 70656 67584 29696 44032 80896 22528 1024 52224 2 75 71 68 31 45 81 24 3 53
output:
13
result:
wrong answer 1st numbers differ - expected: '12', found: '13'