結果

問題 No.911 ラッキーソート
ユーザー kappybarkappybar
提出日時 2020-04-07 18:24:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,407 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 176,728 KB
実行使用メモリ 25,868 KB
最終ジャッジ日時 2023-09-22 03:43:06
合計ジャッジ時間 19,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,288 KB
testcase_01 AC 5 ms
9,288 KB
testcase_02 AC 4 ms
8,996 KB
testcase_03 WA -
testcase_04 AC 5 ms
9,052 KB
testcase_05 WA -
testcase_06 AC 5 ms
9,140 KB
testcase_07 AC 5 ms
9,116 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
9,112 KB
testcase_11 WA -
testcase_12 AC 5 ms
9,204 KB
testcase_13 WA -
testcase_14 AC 537 ms
25,748 KB
testcase_15 AC 565 ms
25,668 KB
testcase_16 AC 573 ms
25,728 KB
testcase_17 AC 584 ms
25,652 KB
testcase_18 WA -
testcase_19 AC 576 ms
25,868 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 455 ms
23,956 KB
testcase_24 WA -
testcase_25 AC 221 ms
18,192 KB
testcase_26 AC 165 ms
15,748 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 7 ms
9,116 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 6 ms
9,000 KB
testcase_34 WA -
testcase_35 AC 5 ms
9,000 KB
testcase_36 AC 5 ms
9,112 KB
testcase_37 AC 5 ms
9,316 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 11 ms
9,844 KB
testcase_41 AC 575 ms
25,588 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 561 ms
25,668 KB
testcase_45 AC 560 ms
25,848 KB
testcase_46 AC 374 ms
25,656 KB
testcase_47 AC 544 ms
25,612 KB
testcase_48 AC 354 ms
24,900 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 ++;
            }
            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);
        g_cnt = 0;
        rep(j,n-1){
            group[j] = g_cnt;
            if(a[j][i] != a[j+1][i]) g_cnt ++;
        }
        group[n-1] = g_cnt;
        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;
    }
    ll ans ;
    if(l==0) ans = f(r);
    else ans = f(r) - f(l-1);
    cout << ans << endl;
    return 0;
}
0