結果

問題 No.911 ラッキーソート
ユーザー ferinferin
提出日時 2019-10-19 00:28:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,041 ms / 2,000 ms
コード長 2,189 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 175,712 KB
実行使用メモリ 26,008 KB
最終ジャッジ日時 2023-09-08 03:07:38
合計ジャッジ時間 19,676 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1,041 ms
17,908 KB
testcase_14 AC 1,020 ms
22,272 KB
testcase_15 AC 961 ms
22,076 KB
testcase_16 AC 943 ms
18,968 KB
testcase_17 AC 954 ms
20,996 KB
testcase_18 AC 924 ms
23,056 KB
testcase_19 AC 921 ms
22,600 KB
testcase_20 AC 845 ms
24,828 KB
testcase_21 AC 712 ms
22,340 KB
testcase_22 AC 644 ms
22,212 KB
testcase_23 AC 618 ms
23,076 KB
testcase_24 AC 534 ms
19,892 KB
testcase_25 AC 284 ms
13,976 KB
testcase_26 AC 269 ms
9,716 KB
testcase_27 AC 97 ms
5,964 KB
testcase_28 AC 48 ms
4,816 KB
testcase_29 AC 19 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1,006 ms
22,392 KB
testcase_39 AC 630 ms
21,664 KB
testcase_40 AC 16 ms
4,376 KB
testcase_41 AC 838 ms
26,008 KB
testcase_42 AC 434 ms
14,072 KB
testcase_43 AC 960 ms
17,912 KB
testcase_44 AC 48 ms
8,476 KB
testcase_45 AC 49 ms
9,436 KB
testcase_46 AC 49 ms
8,292 KB
testcase_47 AC 48 ms
8,496 KB
testcase_48 AC 45 ms
8,592 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<ll> a(n);
    REP(i, n) cin >> a[i];

    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]&1LL<<(61-i))); 
            }
            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 {
        vector<vector<ll>> dp(63, vector<ll>(2));
        dp[0][0] = 1;
        REP(i, 62) REP(j, 2) {
            ll bit = !!(x&1LL<<(61-i));
            for(auto k: can[i]) {
                if(j==0 && k > bit) continue;
                dp[i+1][j || k < bit] += 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