結果

問題 No.1504 ヌメロニム
ユーザー KoDKoD
提出日時 2021-05-07 22:48:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,544 ms / 2,000 ms
コード長 5,488 bytes
コンパイル時間 3,769 ms
コンパイル使用メモリ 250,008 KB
実行使用メモリ 158,460 KB
最終ジャッジ日時 2023-10-13 14:08:06
合計ジャッジ時間 35,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 8 ms
4,480 KB
testcase_21 AC 5 ms
4,348 KB
testcase_22 AC 8 ms
4,456 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1,527 ms
158,000 KB
testcase_25 AC 713 ms
80,356 KB
testcase_26 AC 1,544 ms
158,156 KB
testcase_27 AC 718 ms
80,096 KB
testcase_28 AC 716 ms
80,296 KB
testcase_29 AC 1,531 ms
158,128 KB
testcase_30 AC 1,521 ms
158,248 KB
testcase_31 AC 711 ms
79,860 KB
testcase_32 AC 713 ms
79,984 KB
testcase_33 AC 1,526 ms
158,232 KB
testcase_34 AC 155 ms
21,520 KB
testcase_35 AC 155 ms
21,412 KB
testcase_36 AC 715 ms
79,532 KB
testcase_37 AC 73 ms
12,108 KB
testcase_38 AC 1,534 ms
158,160 KB
testcase_39 AC 1,533 ms
158,248 KB
testcase_40 AC 1,532 ms
158,316 KB
testcase_41 AC 1,528 ms
158,432 KB
testcase_42 AC 1,529 ms
158,216 KB
testcase_43 AC 1,526 ms
158,228 KB
testcase_44 AC 1,525 ms
158,364 KB
testcase_45 AC 1,525 ms
158,460 KB
testcase_46 AC 1,535 ms
158,216 KB
testcase_47 AC 1,522 ms
158,228 KB
testcase_48 AC 720 ms
79,824 KB
testcase_49 AC 719 ms
80,152 KB
testcase_50 AC 8 ms
4,352 KB
testcase_51 AC 5 ms
4,348 KB
testcase_52 AC 1 ms
4,352 KB
testcase_53 AC 5 ms
4,352 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 155 ms
21,496 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/convolution>
#include <atcoder/modint>

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept {
            return itr != other.itr;
        }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr rep(const usize first, const usize last) noexcept
        : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

class revrep {
    struct Iter {
        usize itr;
        constexpr Iter(const usize pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { --itr; }
        constexpr bool operator!=(const Iter& other) const noexcept {
            return itr != other.itr;
        }
        constexpr usize operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr revrep(const usize first, const usize last) noexcept
        : first(last - 1), last(std::min(first, last) - 1) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

constexpr u64 ceil_log2(const u64 x) {
    u64 e = 0;
    while (((u64)1 << e) < x) ++e;
    return e;
}

template <class F> class AutoRealloc {
    using R = typename decltype(std::declval<F>()((usize)0))::value_type;

    F func;
    mutable std::vector<R> data;

  public:
    template <class G>
    explicit AutoRealloc(G&& g) : func(std::forward<G>(g)), data() {}

    void reserve(const usize size) const {
        if (data.size() < size) data = func(((usize)1 << ceil_log2(size)));
    }
    R operator[](const usize i) const {
        reserve(i + 1);
        return data[i];
    }
};

template <class G> explicit AutoRealloc(G&&) -> AutoRealloc<std::decay_t<G>>;

template <class M> struct ModintUtil {
    static inline const auto fact = AutoRealloc([](const usize n) {
        std::vector<M> ret(n);
        ret[0] = M(1);
        for (const usize i : rep(1, n)) {
            ret[i] = ret[i - 1] * M(i);
        }
        return ret;
    });
    static inline const auto inv = AutoRealloc([](const usize n) {
        std::vector<M> ret(n);
        if (n == 1) return ret;
        ret[1] = M(1);
        for (const usize i : rep(2, n)) {
            ret[i] = -M(M::mod() / i) * ret[M::mod() % i];
        }
        return ret;
    });
    static inline const auto inv_fact = AutoRealloc([](const usize n) {
        std::vector<M> ret(n);
        ret[0] = M(1);
        for (const usize i : rep(1, n)) {
            ret[i] = ret[i - 1] * inv[i];
        }
        return ret;
    });
    static M binom(const usize n, const usize k) {
        assert(k <= n);
        return fact[n] * inv_fact[n - k] * inv_fact[k];
    }
    static M factpow(const usize n, const usize k) {
        assert(k <= n);
        return fact[n] * inv_fact[n - k];
    }
    static M homo(const usize n, const usize k) {
        if (n == 0 and k == 0) return M(1);
        return binom(n + k - 1, k);
    }
};

template <class T> using Vec = std::vector<T>;

using Fp = atcoder::modint998244353;
using Util = ModintUtil<Fp>;
using Poly = Vec<Fp>;

void operator+=(Poly& p, const Poly& q) {
    if (p.size() < q.size()) {
        p.resize(q.size(), Fp(0));
    }
    for (const auto i : rep(0, q.size())) {
        p[i] += q[i];
    }
}

Poly operator*(const Poly& p, const Poly& q) {
    return atcoder::convolution(p, q);
}

struct Data {
    Vec<Fp> left0, right1;
    Data() : left0(1, Fp(0)), right1(1, Fp(0)) {}
};

void F_main() {
    usize N;
    std::cin >> N;
    Vec<bool> S(N);
    for (const auto i : rep(0, N)) {
        char c;
        std::cin >> c;
        S[i] = (c == 'n');
    }
    const usize H = ceil_log2(N);
    const usize M = 1 << H;
    Vec<Data> data(2 * M);
    for (const auto i : rep(0, N)) {
        if (S[i]) {
            data[M + i].right1[0] = Fp(1);
        } else {
            data[M + i].left0[0] = Fp(1);
        }
    }
    Vec<Fp> ans(N - 1);
    Vec<Fp> mul;
    for (const auto i : revrep(1, M)) {
        {
            usize idx = 0;
            for (const auto x : data[2 * i].left0* data[2 * i + 1].right1) {
                if (idx <= N - 2) {
                    ans[idx] += x;
                }
                idx += 1;
            }
        }
        const auto size = data[2 * i].left0.size();
        if (mul.size() < size + 1) {
            mul.assign(size + 1, Fp(0));
            for (const auto i : rep(0, size + 1)) {
                mul[i] = Util::binom(size, i);
            }
        }
        data[i].left0 = std::move(data[2 * i + 1].left0);
        data[i].left0 += data[2 * i].left0 * mul;
        data[i].right1 = std::move(data[2 * i].right1);
        data[i].right1 += data[2 * i + 1].right1 * mul;
    }
    u32 sum = 0;
    for (const auto x : ans) {
        sum ^= x.val();
    }
    std::cout << sum << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    F_main();
    return 0;
}
0