結果

問題 No.911 ラッキーソート
ユーザー kappybarkappybar
提出日時 2020-04-07 20:16:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 699 ms / 2,000 ms
コード長 2,638 bytes
コンパイル時間 1,881 ms
コンパイル使用メモリ 177,036 KB
実行使用メモリ 26,780 KB
最終ジャッジ日時 2023-09-22 07:34:12
合計ジャッジ時間 19,614 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,120 KB
testcase_01 AC 3 ms
9,204 KB
testcase_02 AC 4 ms
9,072 KB
testcase_03 AC 4 ms
9,196 KB
testcase_04 AC 4 ms
9,028 KB
testcase_05 AC 4 ms
9,192 KB
testcase_06 AC 4 ms
9,216 KB
testcase_07 AC 4 ms
9,256 KB
testcase_08 AC 4 ms
9,228 KB
testcase_09 AC 4 ms
9,192 KB
testcase_10 AC 4 ms
9,024 KB
testcase_11 AC 4 ms
9,028 KB
testcase_12 AC 4 ms
8,136 KB
testcase_13 AC 699 ms
26,496 KB
testcase_14 AC 695 ms
26,492 KB
testcase_15 AC 677 ms
26,560 KB
testcase_16 AC 690 ms
26,536 KB
testcase_17 AC 692 ms
26,616 KB
testcase_18 AC 686 ms
26,476 KB
testcase_19 AC 691 ms
26,464 KB
testcase_20 AC 658 ms
26,472 KB
testcase_21 AC 621 ms
26,232 KB
testcase_22 AC 584 ms
26,020 KB
testcase_23 AC 564 ms
24,944 KB
testcase_24 AC 501 ms
23,320 KB
testcase_25 AC 296 ms
18,284 KB
testcase_26 AC 249 ms
16,004 KB
testcase_27 AC 103 ms
12,588 KB
testcase_28 AC 52 ms
11,008 KB
testcase_29 AC 17 ms
9,896 KB
testcase_30 AC 6 ms
9,256 KB
testcase_31 AC 4 ms
9,080 KB
testcase_32 AC 4 ms
9,152 KB
testcase_33 AC 3 ms
8,092 KB
testcase_34 AC 4 ms
9,252 KB
testcase_35 AC 4 ms
8,076 KB
testcase_36 AC 4 ms
9,196 KB
testcase_37 AC 4 ms
9,024 KB
testcase_38 AC 686 ms
26,548 KB
testcase_39 AC 571 ms
25,204 KB
testcase_40 AC 13 ms
9,784 KB
testcase_41 AC 659 ms
26,532 KB
testcase_42 AC 259 ms
20,140 KB
testcase_43 AC 691 ms
26,496 KB
testcase_44 AC 434 ms
26,508 KB
testcase_45 AC 424 ms
26,780 KB
testcase_46 AC 315 ms
26,668 KB
testcase_47 AC 443 ms
26,480 KB
testcase_48 AC 292 ms
25,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using pp = pair<bool,bool>;
const int INF = 1e9;
const int MOD = 1000000007;
int n = 200005;
vector<string> a(n);

ll f(ll x){
    bitset<64> bit(x);
    string s = bit.to_string();
    vector<vector<ll>> dp(65,vector<ll>(2,0));
    vector<int> group(n,0);
    int g_cnt = 1;
    dp[0][0] = 1;

    auto one_zero_ok = [&](int i){
        bool ok = true;
        vector<bool> flg(4,false);
        int g = 0,idx = 0;
        while(g < g_cnt){
            bool one = false,zero = false;
            int c = 0;
            while(idx < n){
                if(group[idx] != g) break;
                if(a[idx][i] =='1' && !one) one = true,zero = false,c++;
                else if(a[idx][i] =='0' && !zero) zero = true,one = false,c++;
                idx ++;
            }
            //cout << c << endl;
            if(c==2 && one) flg[0] = true;
            else if(c==2 && zero) flg[1] = true;
            else if(c==1 && zero) flg[2] = true;
            else if(c==1 && one) flg[3] = true;
            else ok = false;
            ++g;
        }
        if(!ok) return pp(false,false);
        //rep(j,4) cout << flg[j] ? "Y" : "N" ;
        //cout << endl;
        vector<int> pre_group(n,0);
        g_cnt = 0;
        rep(j,n-1){
            pre_group[j] = g_cnt;
            if((a[j][i] != a[j+1][i])||(group[j] != group[j+1])) g_cnt ++;
        }
        pre_group[n-1] = g_cnt;
        swap(pre_group,group);
        g_cnt ++;
        pp res = pp(true,true);
        if(flg[0]) res.second = false;
        if(flg[1]) res.first = false;
        return res;
    };

    for(int i=1;i<65;i++){
        bool one_ok,zero_ok;
        tie(zero_ok,one_ok) = one_zero_ok(i-1);
        if(s[i-1] == '1'){
            if(one_ok){
                dp[i][0] += dp[i-1][0];
                dp[i][1] += dp[i-1][1];
            }if(zero_ok){
                dp[i][1] += dp[i-1][0] + dp[i-1][1];
            }
        }else{
            if(one_ok){
                dp[i][1] += dp[i-1][1];
            }if(zero_ok){
                dp[i][1] += dp[i-1][1];
                dp[i][0] += dp[i-1][0];
            }
        }
    }
    if(g_cnt != n) return 0;
    else return dp[64][0] + dp[64][1];
}

int main(){
    ll l,r;
    cin >> n >> l >> r;
    rep(i,n){
        ll p;
        cin >> p;
        bitset<64> b(p);
        string bi = b.to_string();
        a[i] = bi;
        //cout << a[i] << endl;
    }
    ll ans ;
    if(l==0) ans = f(r);
    else ans = f(r) - f(l-1);
    cout << ans << endl;
    return 0;
}
0