結果

問題 No.911 ラッキーソート
ユーザー yosupotyosupot
提出日時 2019-10-18 21:37:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,826 bytes
コンパイル時間 3,700 ms
コンパイル使用メモリ 209,784 KB
実行使用メモリ 4,796 KB
最終ジャッジ日時 2023-09-07 21:35:28
合計ジャッジ時間 6,065 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 49 ms
4,796 KB
testcase_14 AC 51 ms
4,608 KB
testcase_15 AC 50 ms
4,552 KB
testcase_16 AC 54 ms
4,592 KB
testcase_17 AC 52 ms
4,700 KB
testcase_18 AC 52 ms
4,636 KB
testcase_19 AC 51 ms
4,612 KB
testcase_20 AC 52 ms
4,704 KB
testcase_21 AC 54 ms
4,568 KB
testcase_22 AC 53 ms
4,716 KB
testcase_23 AC 50 ms
4,380 KB
testcase_24 AC 44 ms
4,436 KB
testcase_25 AC 30 ms
4,376 KB
testcase_26 AC 23 ms
4,380 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 52 ms
4,592 KB
testcase_39 AC 53 ms
4,624 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 53 ms
4,756 KB
testcase_42 AC 35 ms
4,376 KB
testcase_43 AC 52 ms
4,696 KB
testcase_44 AC 41 ms
4,600 KB
testcase_45 AC 43 ms
4,556 KB
testcase_46 AC 42 ms
4,556 KB
testcase_47 AC 42 ms
4,568 KB
testcase_48 AC 41 ms
4,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

ll up;
V<int> fix(62, -1);

using S = pair<int, bool>;
map<S, ll> dp;
ll solve(int he, bool same) {
    if (he == -1) return 1;
    auto key = S(he, same);
    if (dp.count(key)) return dp[key];
    ll ans = 0;
    ll nw = (up >> he) & 1;
    if (fix[he] != 1) {
        ans += solve(he - 1, (same) && nw == 0);
    }
    if (fix[he] != 0 && !(same && nw == 0)) {
        ans += solve(he - 1, (same) && nw == 1);
    }
    return dp[key] = ans;
}

ll solve(ll x) {
    up = x;
    dp.clear();
    return solve(61, true);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    ll l, r;
    cin >> n >> l >> r;
    V<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n - 1; i++) {
        ll x = a[i], y = a[i + 1];
        for (int he = 61; he >= 0; he--) {
            ll u = (x >> he) & 1;
            ll v = (y >> he) & 1;
            if (u == v) continue;
            dbg(x, y, u, v, he);

            if (u < v) {
                if (fix[he] == 1) {
                    cout << 0 << endl;
                    return 0;
                }
                fix[he] = 0;
            } else {
                if (fix[he] == 0) {
                    cout << 0 << endl;
                    return 0;
                }
                fix[he] = 1;
            }
            break;
        }
    }
    dbg(fix);
    ll ans = solve(r);
    if (l) ans -= solve(l - 1);
    cout << ans << endl;
    return 0;
}
0