QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204421#7560. Computer Networkucup-team870#WA 1ms7976kbC++141.1kb2023-10-07 11:20:282023-10-07 11:20:28

Judging History

你现在查看的是最新测评结果

  • [2023-10-07 11:20:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7976kb
  • [2023-10-07 11:20:28]
  • 提交

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];
            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); break;
            }
        }
    }
    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: 1ms
memory: 7932kb

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: 7976kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 7932kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7668kb

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 7704kb

input:

1
249912
43

output:

32

result:

wrong answer 1st numbers differ - expected: '26', found: '32'