結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 1 ms
6,940 KB
testcase_13 WA -
testcase_14 AC 233 ms
21,720 KB
testcase_15 AC 237 ms
27,772 KB
testcase_16 AC 239 ms
21,424 KB
testcase_17 AC 237 ms
21,220 KB
testcase_18 WA -
testcase_19 AC 240 ms
20,992 KB
testcase_20 WA -
testcase_21 AC 251 ms
27,512 KB
testcase_22 AC 243 ms
21,768 KB
testcase_23 AC 230 ms
20,312 KB
testcase_24 WA -
testcase_25 AC 133 ms
18,508 KB
testcase_26 AC 104 ms
9,392 KB
testcase_27 AC 50 ms
6,940 KB
testcase_28 AC 26 ms
6,940 KB
testcase_29 AC 8 ms
6,940 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 WA -
testcase_39 AC 238 ms
21,400 KB
testcase_40 AC 7 ms
6,940 KB
testcase_41 AC 237 ms
22,404 KB
testcase_42 AC 156 ms
15,072 KB
testcase_43 AC 233 ms
21,180 KB
testcase_44 AC 153 ms
14,300 KB
testcase_45 AC 172 ms
17,652 KB
testcase_46 AC 186 ms
18,916 KB
testcase_47 AC 154 ms
14,156 KB
testcase_48 AC 137 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

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){
        for (int i = f(r)+1; i <= 63; i++) {
            if(v[i]) return 0LL;
        }
        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