結果

問題 No.911 ラッキーソート
ユーザー IKyoproIKyopro
提出日時 2019-10-18 23:40:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 76,268 KB
実行使用メモリ 4,920 KB
最終ジャッジ日時 2023-09-08 02:50:35
合計ジャッジ時間 6,680 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 142 ms
4,688 KB
testcase_14 AC 146 ms
4,688 KB
testcase_15 AC 145 ms
4,732 KB
testcase_16 AC 149 ms
4,912 KB
testcase_17 AC 148 ms
4,620 KB
testcase_18 AC 148 ms
4,568 KB
testcase_19 AC 145 ms
4,920 KB
testcase_20 AC 145 ms
4,736 KB
testcase_21 AC 147 ms
4,668 KB
testcase_22 AC 146 ms
4,624 KB
testcase_23 AC 136 ms
4,380 KB
testcase_24 AC 125 ms
4,436 KB
testcase_25 AC 79 ms
4,376 KB
testcase_26 AC 61 ms
4,376 KB
testcase_27 AC 31 ms
4,380 KB
testcase_28 AC 16 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 147 ms
4,572 KB
testcase_39 AC 142 ms
4,472 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 146 ms
4,620 KB
testcase_42 AC 94 ms
4,376 KB
testcase_43 AC 146 ms
4,580 KB
testcase_44 AC 143 ms
4,696 KB
testcase_45 AC 146 ms
4,668 KB
testcase_46 AC 146 ms
4,736 KB
testcase_47 AC 144 ms
4,676 KB
testcase_48 AC 142 ms
4,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
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;
    }
    auto 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