結果

問題 No.911 ラッキーソート
ユーザー treeonetreeone
提出日時 2019-08-27 00:39:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,527 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 207,932 KB
実行使用メモリ 9,364 KB
最終ジャッジ日時 2023-08-11 04:14:09
合計ジャッジ時間 12,111 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 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 408 ms
9,340 KB
testcase_14 AC 379 ms
9,296 KB
testcase_15 AC 358 ms
9,308 KB
testcase_16 AC 355 ms
9,184 KB
testcase_17 AC 335 ms
9,040 KB
testcase_18 AC 326 ms
8,388 KB
testcase_19 AC 319 ms
8,436 KB
testcase_20 AC 297 ms
7,652 KB
testcase_21 AC 272 ms
7,548 KB
testcase_22 AC 248 ms
7,488 KB
testcase_23 AC 223 ms
7,088 KB
testcase_24 WA -
testcase_25 AC 113 ms
5,120 KB
testcase_26 AC 92 ms
4,656 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 399 ms
9,236 KB
testcase_39 AC 237 ms
7,128 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 291 ms
7,624 KB
testcase_42 WA -
testcase_43 AC 362 ms
9,044 KB
testcase_44 AC 383 ms
9,364 KB
testcase_45 AC 357 ms
8,496 KB
testcase_46 AC 346 ms
7,676 KB
testcase_47 AC 312 ms
7,816 KB
testcase_48 AC 293 ms
8,288 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;
    }
    int ans = calc(R);
    if(L != 0) ans -= calc(L - 1);
    cout << ans << endl;
}
0