結果

問題 No.911 ラッキーソート
ユーザー latte0119latte0119
提出日時 2019-10-18 22:11:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,635 bytes
コンパイル時間 2,740 ms
コンパイル使用メモリ 144,424 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-09-07 23:50:39
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 135 ms
4,924 KB
testcase_14 AC 140 ms
4,876 KB
testcase_15 AC 137 ms
4,896 KB
testcase_16 AC 141 ms
4,900 KB
testcase_17 AC 140 ms
4,908 KB
testcase_18 AC 141 ms
4,892 KB
testcase_19 AC 140 ms
4,956 KB
testcase_20 AC 137 ms
4,896 KB
testcase_21 AC 140 ms
4,872 KB
testcase_22 AC 137 ms
4,892 KB
testcase_23 AC 127 ms
5,040 KB
testcase_24 AC 116 ms
4,908 KB
testcase_25 AC 74 ms
4,384 KB
testcase_26 AC 56 ms
4,376 KB
testcase_27 AC 28 ms
4,376 KB
testcase_28 AC 15 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 141 ms
4,900 KB
testcase_39 AC 137 ms
4,752 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 139 ms
4,888 KB
testcase_42 AC 90 ms
4,376 KB
testcase_43 AC 139 ms
5,196 KB
testcase_44 AC 136 ms
5,200 KB
testcase_45 AC 140 ms
4,892 KB
testcase_46 AC 140 ms
4,904 KB
testcase_47 AC 136 ms
4,888 KB
testcase_48 AC 135 ms
4,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int uku[66];

int calc(int X){
    int la=1,ma=0;
    for(int i=60;i>=0;i--){
        int lala=0,mama=0;
        for(int b=0;b<2;b++){
            if(uku[i]!=-1&&uku[i]!=b)continue;
            mama+=ma;
            if((X>>i&1)==b)lala+=la;
            else if((X>>i&1)>b)mama+=la;
        }
        la=lala;
        ma=mama;
    }
    return la+ma;
}

int N,L,R;
int A[222222];

signed main(){
    cin>>N>>L>>R;
    rep(i,N)cin>>A[i];
    memset(uku,-1,sizeof(uku));
    bool ok=true;
    rep(i,N-1){
        for(int k=60;k>=0;k--){
            if((A[i]>>k&1)==(A[i+1]>>k&1))continue;
            int b;
            if(A[i]>>k&1)b=1;
            else b=0;
            if(uku[k]!=-1&&uku[k]!=b)ok=false;
            uku[k]=b;
            break;
        }
    }
    if(!ok){
        cout<<0<<endl;
        return 0;
    }

    int ans=calc(R);
    if(L)ans-=calc(L-1);
    cout<<ans<<endl;
	return 0;
}
0