結果

問題 No.911 ラッキーソート
ユーザー IKyoproIKyopro
提出日時 2019-10-18 22:46:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,728 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 92,052 KB
実行使用メモリ 4,908 KB
最終ジャッジ日時 2023-09-08 00:46:29
合計ジャッジ時間 6,908 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 135 ms
4,712 KB
testcase_14 AC 141 ms
4,596 KB
testcase_15 AC 138 ms
4,576 KB
testcase_16 AC 142 ms
4,620 KB
testcase_17 AC 141 ms
4,696 KB
testcase_18 AC 142 ms
4,868 KB
testcase_19 AC 139 ms
4,652 KB
testcase_20 AC 139 ms
4,756 KB
testcase_21 AC 140 ms
4,884 KB
testcase_22 AC 137 ms
4,908 KB
testcase_23 AC 130 ms
4,380 KB
testcase_24 AC 117 ms
4,460 KB
testcase_25 AC 76 ms
4,376 KB
testcase_26 AC 58 ms
4,380 KB
testcase_27 AC 29 ms
4,380 KB
testcase_28 AC 16 ms
4,380 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 142 ms
4,588 KB
testcase_39 AC 137 ms
4,380 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 139 ms
4,640 KB
testcase_42 AC 92 ms
4,392 KB
testcase_43 AC 143 ms
4,908 KB
testcase_44 AC 139 ms
4,656 KB
testcase_45 AC 143 ms
4,588 KB
testcase_46 AC 145 ms
4,568 KB
testcase_47 AC 138 ms
4,576 KB
testcase_48 AC 139 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <functional>
using namespace std;
typedef long long ll;

int main(){
    ll N,L,R;
    cin >> N >> L >> R;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    vector<int> r(61,-1);
    bool ok = true;
    for(int i=0;i<N-1;i++){
        for(int j=60;j>=0;j--){
            if((A[i+1]&(1LL<<j)) && !(A[i]&(1LL<<j))){
                if(r[j]==1) ok = false;
                r[j] = 0;
                break;
            }
            if(!(A[i+1]&(1LL<<j)) && (A[i]&(1LL<<j))){
                if(r[j]==0) ok = false;
                r[j] = 1;
                break;
            }
        }
    }
    if(!ok){
        cout << 0 << endl;
        return 0;
    }
    function<ll(ll)> calc = [&](ll x){
        int h = 0;
        for(int j=0;j<61;j++){
            if(x&(1LL<<j)) h = j;
        }
        for(int j=h+1;j<61;j++) if(r[j]==1) return 0LL;
        ll dp[70][2][2] = {};
        dp[h+1][0][0] = 1;
        for(int i=h;i>=0;i--){
            for(int nj=0;nj<2;nj++){
                if(nj==0 && r[i]==1) continue;
                if(nj==1 && r[i]==0) continue;
                for(int j=0;j<2;j++){
                    for(int k=0;k<2;k++){
                        if(!(x&(1LL<<i)) && k==0 && nj==1) continue;
                        int nk = 1;
                        if(!(x&(1LL<<i)) && k==0 && nj==0) nk = 0;
                        if((x&(1LL<<i)) && k==0 && nj==1) nk = 0;
                        dp[i][nj][nk] += dp[i+1][j][k];
                    }
                }
            }
        }
        ll res = 0;
        for(int j=0;j<2;j++) for(int k=0;k<2;k++) res += dp[0][j][k];
        return res;
    };
    cout << calc(R)-(L!=0? calc(L-1):0) << endl;
}
0