QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224676#7560. Computer NetworkGiga_Cronos#WA 0ms3876kbC++142.1kb2023-10-23 09:02:282023-10-23 09:02:29

Judging History

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

  • [2023-10-23 09:02:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3876kb
  • [2023-10-23 09:02:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fs first 
#define sc second
#define pb push_back
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int qpow(int a,int e,int mod){
        if(e==0)return 1;
        if(e==1)return a;
        if(e%2){
            return a*qpow(a,e-1,mod)%mod;
        }else{
            int c=qpow(a,e/2,mod);
            return c*c%mod;
        }
}


pii Intersect(pii A,pii B){
    if(A>B)swap(A,B);
    if(A.sc<B.fs){
        return {-1,-1};
    }
    vi C;
    C.pb(A.fs);C.pb(A.sc);C.pb(B.fs);C.pb(B.sc);
    sort(all(C));
    return {C[1],C[2]};
}

int Descomp(pii R,int b){
    int best=numeric_limits<int>::max();
    int cur=0;
    for(int i=30;i>=0;i--){
        
        if(i>b){
           if((bool)(R.fs&(1ll<<i))==(bool)(R.sc&(1ll<<i))){
             if((bool)(R.fs&(1ll<<i))){
             cur+=(1ll<<(i-b)); 
             }
                 
           }else{
            best=min(best,cur+(1ll<<(i-b)));
           R.sc=(1ll<<i)-1;
           } 
        }else{
           if((bool)(R.fs&(1ll<<i))==(bool)(R.sc&(1ll<<i))){
             if((bool)(R.fs&(1ll<<i)))
             cur++;
                 
           }else{
            best=min(best,cur+1);
            break;
           } 
        }
        if(i==0){
            best=min(best,cur);
        }
       
    }
    return best;

}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    vi A(n);
    vi B(n);
    for(auto &a:A)cin>>a;
    for(auto &b:B)cin>>b;
    int ans=numeric_limits<int>::max();
    for(int i=0;i<=30;i++){
        pii R={0,numeric_limits<int>::max()};
        for(int j=0;j<n;j++)if(R.fs!=-1){
        pii s={B[j]*(1ll<<i),B[j]*(1ll<<i)+(1ll<<i)-1};
        s.fs-=A[j];
        s.sc-=A[j];
        R=Intersect(s,R);
        }
        if(R.fs==-1)continue;
        ans=min(ans,Descomp(R,i)+i);   
    }
   
    if(ans==numeric_limits<int>::max()){
        cout<<-1;
        return 0;
    }
    cout<<ans;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

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

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

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

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

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

input:

1
249912
43

output:

26

result:

ok 1 number(s): "26"

Test #6:

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

input:

2
52522336 155670
52532336 165670

output:

10000

result:

ok 1 number(s): "10000"

Test #7:

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

input:

2
141839218 538313890
17731054 67290388

output:

1155

result:

ok 1 number(s): "1155"

Test #8:

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

input:

2
678834913 571995689
84855772 71500869

output:

1411

result:

ok 1 number(s): "1411"

Test #9:

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

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: 0ms
memory: 3876kb

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'