QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205110#7560. Computer Networkucup-team1134#WA 0ms3828kbC++173.8kb2023-10-07 14:53:482023-10-07 14:53:48

Judging History

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

  • [2023-10-07 14:53:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2023-10-07 14:53:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int solve(ll l,ll r){
    r--;
    if(l==r) return __builtin_popcountll(l);
    int res=0;
    for(int t=33;t>=0;t--){
        if((l&(1LL<<t))==(r&(1LL<<t))){
            if((l&(1LL<<t))) res++;
        }else{
            res++;
            break;
        }
    }
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<ll,ll>> S(N);
    for(int i=0;i<N;i++) cin>>S[i].fi;
    for(int i=0;i<N;i++) cin>>S[i].se;
    
    sort(all(S));
    
    for(int i=0;i+1<N;i++){
        if(S[i].se>S[i+1].se){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    ll ans=1LL<<60;
    
    for(int t=0;t<35;t++){
        if(t){
            vector<pair<ll,ll>> X,Y;
            for(int i=0;i<N;i++){
                if(S[i].fi&(1LL<<(t-1))) X.push_back(S[i]);
                else Y.push_back(S[i]);
            }
            S.clear();
            for(auto a:X) S.push_back(a);
            for(auto a:Y) S.push_back(a);
        }
        vector<ll> A(N),B(N);
        for(int i=0;i<N;i++){
            A[i]=S[i].fi;
            B[i]=S[i].se;
        }
        
        vector<pair<ll,ll>> kukan={mp(0,1LL<<t)};
        
        for(int i=0;i+1<N;i++){
            ll a=0,b=(1LL<<t)-A[i]%(1LL<<t),c=(1LL<<t)-A[i+1]%(1LL<<t),d=(1LL<<t);
            
            vector<pair<ll,ll>> nex;
            
            if(b==c){
                if(((A[i]+a)>>t)-((A[i+1]+a)>>t)==B[i]-B[i+1]){
                    if(((A[i]+b)>>t)-((A[i+1]+b)>>t)==B[i]-B[i+1]){
                        nex=kukan;
                    }else{
                        for(auto [l,r]:kukan){
                            ll L=max(l,a),R=min(r,b);
                            if(L<R) nex.push_back(mp(L,R));
                        }
                    }
                }else{
                    if(((A[i]+b)>>t)-((A[i+1]+b)>>t)==B[i]-B[i+1]){
                        for(auto [l,r]:kukan){
                            ll L=max(l,c),R=min(r,d);
                            if(L<R) nex.push_back(mp(L,R));
                        }
                    }else{
                        
                    }
                }
            }else{
                if(((A[i]+a)>>t)-((A[i+1]+a)>>t)==B[i]-B[i+1]){
                    for(auto [l,r]:kukan){
                        {
                            ll L=max(l,a),R=min(r,b);
                            if(L<R) nex.push_back(mp(L,R));
                        }
                        {
                            ll L=max(l,c),R=min(r,d);
                            if(L<R) nex.push_back(mp(L,R));
                        }
                    }
                }else{
                    if(((A[i]+b)>>t)-((A[i+1]+b)>>t)==B[i]-B[i+1]){
                        for(auto [l,r]:kukan){
                            ll L=max(l,b),R=min(r,c);
                            if(L<R) nex.push_back(mp(L,R));
                        }
                    }
                }
            }
            
            kukan=nex;
            
            if(si(kukan)==0) break;
        }
        
        for(auto [l,r]:kukan){
            if(((A[0]+l)>>t)<=B[0]){
                chmin(ans,B[0]-((A[0]+l)>>t)+t+solve(l,r));
            }
        }
    }
    
    if(ans==(1LL<<60)) ans=-1;
    
    cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

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

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

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

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3828kb

input:

1
249912
43

output:

27

result:

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