QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#204439 | #7560. Computer Network | ucup-team870# | WA | 1ms | 7764kb | C++14 | 1.2kb | 2023-10-07 11:36:18 | 2023-10-07 11:36:19 |
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 (ll)__builtin_popcountll(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
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7724kb
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: 0ms
memory: 7736kb
input:
3 2 3 4 1 2 3
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7672kb
input:
2 65536 65537 1 2
output:
32
result:
ok 1 number(s): "32"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7764kb
input:
1 0 28
output:
28
result:
ok 1 number(s): "28"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 7668kb
input:
1 249912 43
output:
32
result:
wrong answer 1st numbers differ - expected: '26', found: '32'