結果

問題 No.911 ラッキーソート
ユーザー TAISA_TAISA_
提出日時 2019-10-21 00:25:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,615 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 173,476 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-09-15 14:50:55
合計ジャッジ時間 5,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 46 ms
4,572 KB
testcase_15 AC 44 ms
4,640 KB
testcase_16 AC 46 ms
4,560 KB
testcase_17 AC 45 ms
4,612 KB
testcase_18 WA -
testcase_19 AC 45 ms
4,644 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 37 ms
4,384 KB
testcase_24 WA -
testcase_25 AC 23 ms
4,376 KB
testcase_26 AC 18 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 44 ms
4,564 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 40 ms
4,628 KB
testcase_45 AC 42 ms
4,628 KB
testcase_46 AC 41 ms
4,676 KB
testcase_47 AC 41 ms
4,644 KB
testcase_48 AC 38 ms
4,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n;
vector<ll> a;
ll solve(ll ub) {
    ll dp[64][2][2] = {};
    dp[62][0][1] = 1;
    vector<P> v;
    v.push_back(P(0, n - 1));
    for (int i = 61; i >= 0; i--) {
        int c1 = 0, c2 = 0, c3 = 0;
        vector<P> nv;
        for (auto &p : v) {
            int f0 = 0, f1 = 0, t = ((a[p.first] >> i) & 1LL);
            if (t == 0) {
                f0++;
            } else {
                f1++;
            }
            int tm = -1;
            for (int j = p.first + 1; j <= p.second; j++) {
                if ((a[j] >> i) & 1) {
                    if (t == 1) {
                        if (f0 > 0) {
                            // cout << i << endl;
                            return 0;
                        }
                    } else if (f1 == 0) {
                        nv.push_back(P(p.first, j - 1));
                        tm = j - 1;
                    }
                    f1++;
                } else {
                    if (t == 0) {
                        if (f1 > 0) {
                            return 0;
                        }
                    } else if (f0 == 0) {
                        nv.push_back(P(p.first, j - 1));
                        tm = j - 1;
                    }
                    f0++;
                }
            }
            nv.push_back(P(tm + 1, p.second));
            if (f0 == 0 || f1 == 0) {
                c3++;
            } else if (t == 0) {
                c1++;
            } else {
                c2++;
            }
        }
        if (c1 > 0) {
            if (c2 > 0) {
                return 0;
            }
            if ((ub >> i) & 1LL) {
                dp[i][0][0] += dp[i + 1][1][0] + dp[i + 1][0][1] +
                               dp[i + 1][0][0] + dp[i + 1][1][1];
            } else {
                dp[i][0][0] += dp[i + 1][1][0] + dp[i + 1][0][0];
                dp[i][0][1] += dp[i + 1][0][1] + dp[i + 1][1][1];
            }
        } else if (c2 > 0) {
            if (c1 > 0) {
                return 0;
            }
            if ((ub >> i) & 1LL) {
                dp[i][1][0] += dp[i + 1][1][0] + dp[i + 1][0][0];
                dp[i][1][1] += dp[i + 1][0][1] + dp[i + 1][1][1];
            } else {
                dp[i][1][0] += dp[i + 1][1][0] + dp[i + 1][0][0];
            }
        } else {
            if ((ub >> i) & 1LL) {
                dp[i][0][0] += dp[i + 1][0][0] + dp[i + 1][0][1] +
                               dp[i + 1][1][0] + dp[i + 1][1][1];
                dp[i][1][0] += dp[i + 1][0][0] + dp[i + 1][1][0];
                dp[i][1][1] += dp[i + 1][1][1] + dp[i + 1][0][1];
            } else {
                dp[i][1][0] += dp[i + 1][0][0] + dp[i + 1][1][0];
                dp[i][0][0] += dp[i + 1][0][0] + dp[i + 1][1][0];
                dp[i][0][1] += dp[i + 1][1][1] + dp[i + 1][0][1];
            }
        }
        swap(nv, v);
    }
    return dp[0][0][0] + dp[0][0][1] + dp[0][1][0] + dp[0][1][1];
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll l, r;
    cin >> l >> r;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll res = solve(r);
    if (l > 0) {
        res -= solve(l - 1);
    }
    cout << res << endl;
}
0