結果

問題 No.911 ラッキーソート
ユーザー treeonetreeone
提出日時 2019-08-29 22:08:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 207,648 KB
実行使用メモリ 9,432 KB
最終ジャッジ日時 2023-08-11 04:19:28
合計ジャッジ時間 12,949 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 444 ms
9,264 KB
testcase_14 AC 427 ms
9,236 KB
testcase_15 AC 393 ms
9,432 KB
testcase_16 AC 385 ms
9,308 KB
testcase_17 AC 374 ms
9,236 KB
testcase_18 AC 364 ms
8,772 KB
testcase_19 AC 356 ms
8,252 KB
testcase_20 AC 337 ms
7,772 KB
testcase_21 AC 304 ms
7,508 KB
testcase_22 AC 276 ms
7,436 KB
testcase_23 AC 250 ms
7,180 KB
testcase_24 AC 222 ms
6,920 KB
testcase_25 AC 125 ms
4,892 KB
testcase_26 AC 102 ms
4,692 KB
testcase_27 AC 43 ms
4,380 KB
testcase_28 AC 22 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 3 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,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 420 ms
9,292 KB
testcase_39 AC 257 ms
7,196 KB
testcase_40 AC 7 ms
4,376 KB
testcase_41 AC 337 ms
7,752 KB
testcase_42 AC 163 ms
5,796 KB
testcase_43 AC 396 ms
9,104 KB
testcase_44 AC 420 ms
9,268 KB
testcase_45 AC 393 ms
8,472 KB
testcase_46 AC 385 ms
7,796 KB
testcase_47 AC 360 ms
8,020 KB
testcase_48 AC 315 ms
8,216 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