結果

問題 No.911 ラッキーソート
ユーザー ferinferin
提出日時 2019-10-19 00:19:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,020 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 176,352 KB
実行使用メモリ 26,128 KB
最終ジャッジ日時 2023-09-08 03:01:34
合計ジャッジ時間 19,343 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1,020 ms
17,952 KB
testcase_14 AC 1,019 ms
22,260 KB
testcase_15 AC 959 ms
22,112 KB
testcase_16 AC 953 ms
18,844 KB
testcase_17 AC 979 ms
20,908 KB
testcase_18 AC 923 ms
22,956 KB
testcase_19 AC 921 ms
22,812 KB
testcase_20 AC 845 ms
24,916 KB
testcase_21 AC 721 ms
22,212 KB
testcase_22 AC 643 ms
22,340 KB
testcase_23 AC 625 ms
23,132 KB
testcase_24 AC 541 ms
19,784 KB
testcase_25 AC 292 ms
14,020 KB
testcase_26 AC 278 ms
9,540 KB
testcase_27 AC 99 ms
6,024 KB
testcase_28 AC 49 ms
4,668 KB
testcase_29 AC 18 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1,012 ms
22,524 KB
testcase_39 AC 639 ms
21,644 KB
testcase_40 AC 17 ms
4,376 KB
testcase_41 AC 844 ms
26,128 KB
testcase_42 AC 435 ms
14,180 KB
testcase_43 AC 956 ms
18,176 KB
testcase_44 AC 47 ms
8,528 KB
testcase_45 AC 49 ms
9,628 KB
testcase_46 AC 49 ms
8,312 KB
testcase_47 AC 49 ms
8,636 KB
testcase_48 AC 45 ms
8,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, l, r;
    cin >> n >> l >> r;
    vector<bitset<64>> a(n);
    REP(i, n) {
        ll b;
        cin >> b;
        a[i] = bitset<64>(b);
    }

    // REP(i, n) cerr << a[i] << endl;

    vector<vector<ll>> can(62);
    auto func = [&] {
        vector<ll> p;
        REP(i, 62) {
            ll idx = 0;
            vector<vector<ll>> v(p.size()+1);
            REP(j, n) {
                if(idx<(ll)p.size() && p[idx]==j) idx++;
                v[idx].push_back(a[j].test(61-i)); 
            }
            // if(i>=40) {dump(i); dump(p); dump(v);}
            ll sz = 0;
            bool ok0 = true, ok1 = true;
            for(auto vec: v) {
                ll turn = 0;
                REP(j, vec.size()) {
                    if(turn==0 && vec[j]!=vec[0]) turn = 1, p.push_back(sz+j);
                    else if(turn==1 && vec[j]==vec[0]) {
                        cout << 0 << endl;
                        exit(0);
                    }
                }
                if(turn==1) {
                    if(vec[0]==0) ok1 = false;
                    else if(vec[0]==1) ok0 = false;
                } 
                sz += vec.size();
            }
            if(ok0) can[i].push_back(0);
            if(ok1) can[i].push_back(1);
            sort(ALL(p));
        }
    };

    auto solve = [&](ll x) -> ll {
        bitset<64> y(x);
        vector<vector<ll>> dp(63, vector<ll>(2));
        dp[0][0] = 1;
        REP(i, 62) REP(j, 2) {
            for(auto k: can[i]) {
                if(j==0 && k > y.test(61-i)) continue;
                dp[i+1][j || k<y.test(61-i)] += dp[i][j];
            }
        }
        return dp[62][0] + dp[62][1];
    };

    func();
    // dump(can);
    cout << solve(r) - (l==0?0:solve(l-1)) << endl;

    return 0;
}
0