QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204427 | #7560. Computer Network | ucup-team870# | WA | 1ms | 7820kb | C++20 | 1.1kb | 2023-10-07 11:24:20 | 2023-10-07 11:24:20 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pll pair<ll,ll>
const int N=1e6+6;
const ll inf=4e18;
int a[N],b[N];
pll q[N];
int main() {
IOS
int n;cin>>n;
rep(i,1,n)cin>>a[i];
rep(i,1,n)cin>>b[i];
ll ans=inf;
rep(j,0,31){
ll pw=1ll<<j;
ll l=b[1]*pw,r=b[1]*pw+pw-1;
rep(i,2,n){
ll li=b[i]*pw,ri=b[i]*pw+pw-1;
li-=a[i]-a[1]; ri-=a[i]-a[1];
l=max(l,li); r=min(r,ri);
if(l>r)break;
}
// cout<<j<<' '<<l<<' '<<r<<'\n';
auto cal=[&](ll x){
// cout<<x<<'\n';
if(x>pw*b[1])return x-pw*b[1]+b[1];
ll res=x/pw; res+=__builtin_popcountll(x%pw); return res;
};
if(l<=r){
if(r>=a[1]){
ans=min(ans,cal(max(0ll,l-a[1]))+j);
}
}
}
if(ans==inf)cout<<"-1\n";
else cout<<ans<<'\n';
}
/*
5
1 2 3 4 5
6 6 6 6 7
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7820kb
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: 7784kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7780kb
input:
1 0 28
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7764kb
input:
1 249912 43
output:
32
result:
wrong answer 1st numbers differ - expected: '26', found: '32'