結果

問題 No.911 ラッキーソート
ユーザー ゆきのんゆきのん
提出日時 2020-03-10 21:02:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,299 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 173,500 KB
実行使用メモリ 28,256 KB
最終ジャッジ日時 2024-04-27 18:52:13
合計ジャッジ時間 8,109 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 196 ms
22,724 KB
testcase_14 AC 229 ms
21,720 KB
testcase_15 AC 199 ms
27,640 KB
testcase_16 AC 207 ms
21,552 KB
testcase_17 AC 201 ms
21,216 KB
testcase_18 AC 215 ms
24,172 KB
testcase_19 AC 207 ms
20,912 KB
testcase_20 AC 202 ms
23,516 KB
testcase_21 AC 211 ms
27,636 KB
testcase_22 AC 204 ms
21,768 KB
testcase_23 AC 195 ms
20,316 KB
testcase_24 AC 180 ms
17,092 KB
testcase_25 AC 110 ms
18,512 KB
testcase_26 AC 87 ms
9,388 KB
testcase_27 AC 42 ms
6,944 KB
testcase_28 AC 21 ms
6,944 KB
testcase_29 AC 6 ms
6,944 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 1 ms
6,940 KB
testcase_38 AC 204 ms
28,256 KB
testcase_39 AC 200 ms
21,396 KB
testcase_40 AC 7 ms
6,944 KB
testcase_41 AC 201 ms
22,412 KB
testcase_42 AC 134 ms
15,072 KB
testcase_43 AC 198 ms
21,180 KB
testcase_44 WA -
testcase_45 AC 145 ms
17,524 KB
testcase_46 WA -
testcase_47 AC 126 ms
14,148 KB
testcase_48 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<int> v(64,0);

void rec(int k,vector<LL> a){
    if(k < 0) return;
    int n = a.size();
    if(n == 1) return;
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        int t = a[i] >> k & 1, nt = a[i+1] >> k & 1;
        if(t != nt) cnt++;
    }
    if(cnt == 0){
        rec(k-1, a);
    }
    else if(cnt == 1){
        vector<LL> L,R;
        for (int i = 0; i < n; i++) {
            int t = a[i] >> k & 1;
            if(t == 0) L.pb(a[i]);
            else R.pb(a[i]);
        }
        if(a[0] >> k & 1) v[k] |= 2;
        else v[k] |= 1;
        rec(k-1, L);
        rec(k-1, R);
    }
    else{
        v[k] |= 3;
    }
    return ;
}

LL dp[64][2];

LL rec2(int k,LL s,bool f){
    if(k < 0) return 1;
    if(~dp[k][f]) return dp[k][f];
    int x = f ? s >> k & 1 : 1;
    LL ret = 0;
    if(v[k] == 0){
        for (int i = 0; i <= x; i++) {
            ret += rec2(k-1,s,f&(x == i));
        }
    }
    else if(v[k] == 1){
        ret += rec2(k-1,s,f&(x == 0));
    }
    else if(v[k] == 2){
        if(x == 0) return dp[k][f] = 0;
        ret += rec2(k-1,s,f&(x == 1));
    }
    else{
        return dp[k][f] = 0;
    }
    return dp[k][f] = ret;
}

int f(LL n){
    int ret = 0;
    while(n){
        n >>= 1;
        ret++;
    }
    return ret - 1;
}

int main(){
    LL n,l,r;cin >> n >> l >> r;
    l--;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    rec(63,a);
    LL ans = 0;
    auto solve = [](LL r){
        memset(dp,-1,sizeof(dp));
        return rec2(f(r), r, 1);
    };
    ans += solve(r);
    if(l >= 0){
        ans -= solve(l);
    }
    cout << ans << endl;
    return 0;
}
0