結果

問題 No.911 ラッキーソート
ユーザー treeonetreeone
提出日時 2019-08-29 22:08:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 209,696 KB
実行使用メモリ 9,484 KB
最終ジャッジ日時 2024-04-28 21:18:31
合計ジャッジ時間 12,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 433 ms
9,476 KB
testcase_14 AC 414 ms
9,480 KB
testcase_15 AC 383 ms
9,480 KB
testcase_16 AC 378 ms
9,472 KB
testcase_17 AC 359 ms
9,480 KB
testcase_18 AC 346 ms
8,700 KB
testcase_19 AC 337 ms
8,824 KB
testcase_20 AC 320 ms
7,904 KB
testcase_21 AC 291 ms
7,792 KB
testcase_22 AC 265 ms
7,724 KB
testcase_23 AC 245 ms
7,292 KB
testcase_24 AC 216 ms
6,940 KB
testcase_25 AC 123 ms
5,496 KB
testcase_26 AC 100 ms
5,376 KB
testcase_27 AC 43 ms
5,376 KB
testcase_28 AC 22 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 419 ms
9,480 KB
testcase_39 AC 257 ms
7,388 KB
testcase_40 AC 7 ms
5,376 KB
testcase_41 AC 318 ms
8,020 KB
testcase_42 AC 164 ms
5,980 KB
testcase_43 AC 379 ms
9,484 KB
testcase_44 AC 411 ms
9,468 KB
testcase_45 AC 389 ms
8,696 KB
testcase_46 AC 377 ms
7,936 KB
testcase_47 AC 344 ms
7,936 KB
testcase_48 AC 314 ms
8,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int use[61][2];

long long calc(long long M){
    long long dp[2] = {}, nxt[2] = {};
    dp[1] = 1;
    for(int i = 60; i >= 0; i--){
        nxt[0] = nxt[1] = 0;
        nxt[0] += dp[0] * use[i][0];
        nxt[0] += dp[0] * use[i][1];
        if(M & (1LL << i)){
            nxt[0] += dp[1] * use[i][0];
            nxt[1] += dp[1] * use[i][1];
        }else{
            nxt[1] += dp[1] * use[i][0];
        }
        swap(dp, nxt);
    }
    return dp[0] + dp[1];
}

int main(){
    int N;
    long long L, R;
    cin >> N >> L >> R;
    vector<long long> A(N); 
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<int> v;
    v.push_back(0);
    v.push_back(N);
    for(int i = 60; i >= 0; i--){
        use[i][0] = use[i][1] = 1;
        vector<int> tmp = v;
        for(int j = 0; j < v.size() - 1; j++){
            int cnt = 0;
            for(int k = v[j] + 1; k < v[j + 1]; k++){
                if(!!(A[k - 1] & (1LL << i)) != !!(A[k] & (1LL << i))){
                    cnt++;
                    tmp.push_back(k);
                }
            }
            // cout << i << ' ' << j << " " << v[j] << ' ' << cnt << endl;
            if(cnt >= 2) use[i][0] = use[i][1] = 0;
            if(cnt == 1) use[i][!(A[v[j]] & (1LL << i))] = 0;
        }
        sort(tmp.begin(), tmp.end());
        v = tmp;
        // cout << use[i][0] << ' ' << use[i][1] << endl;
    }
    long long ans = calc(R);
    if(L != 0) ans -= calc(L - 1);
    cout << ans << endl;
}
0