結果

問題 No.1504 ヌメロニム
ユーザー MisterMister
提出日時 2021-05-07 22:36:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,990 bytes
コンパイル時間 2,230 ms
コンパイル使用メモリ 118,136 KB
実行使用メモリ 23,544 KB
最終ジャッジ日時 2023-10-13 13:54:30
合計ジャッジ時間 7,754 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,216 KB
testcase_01 AC 6 ms
5,320 KB
testcase_02 AC 6 ms
5,252 KB
testcase_03 AC 6 ms
5,364 KB
testcase_04 AC 6 ms
5,448 KB
testcase_05 AC 6 ms
5,304 KB
testcase_06 AC 7 ms
5,296 KB
testcase_07 AC 6 ms
5,316 KB
testcase_08 AC 6 ms
5,328 KB
testcase_09 AC 6 ms
5,252 KB
testcase_10 AC 6 ms
5,244 KB
testcase_11 AC 6 ms
5,368 KB
testcase_12 AC 6 ms
5,332 KB
testcase_13 AC 6 ms
5,304 KB
testcase_14 AC 6 ms
5,444 KB
testcase_15 AC 6 ms
5,256 KB
testcase_16 AC 7 ms
5,420 KB
testcase_17 AC 6 ms
5,408 KB
testcase_18 AC 6 ms
5,216 KB
testcase_19 AC 6 ms
5,404 KB
testcase_20 AC 7 ms
5,752 KB
testcase_21 AC 6 ms
5,216 KB
testcase_22 AC 7 ms
5,696 KB
testcase_23 AC 6 ms
5,308 KB
testcase_24 AC 161 ms
22,980 KB
testcase_25 AC 88 ms
15,536 KB
testcase_26 AC 162 ms
23,452 KB
testcase_27 AC 90 ms
16,412 KB
testcase_28 AC 89 ms
16,536 KB
testcase_29 AC 158 ms
23,328 KB
testcase_30 AC 159 ms
23,408 KB
testcase_31 AC 86 ms
15,952 KB
testcase_32 AC 88 ms
16,384 KB
testcase_33 AC 160 ms
23,536 KB
testcase_34 AC 25 ms
8,068 KB
testcase_35 AC 24 ms
7,644 KB
testcase_36 AC 83 ms
14,216 KB
testcase_37 AC 15 ms
6,620 KB
testcase_38 AC 164 ms
23,452 KB
testcase_39 AC 163 ms
23,400 KB
testcase_40 AC 159 ms
23,472 KB
testcase_41 AC 160 ms
23,460 KB
testcase_42 AC 161 ms
23,460 KB
testcase_43 AC 161 ms
23,452 KB
testcase_44 AC 160 ms
23,456 KB
testcase_45 AC 160 ms
23,392 KB
testcase_46 AC 163 ms
23,412 KB
testcase_47 AC 163 ms
23,544 KB
testcase_48 AC 85 ms
15,980 KB
testcase_49 AC 84 ms
15,736 KB
testcase_50 AC 7 ms
5,788 KB
testcase_51 AC 7 ms
5,240 KB
testcase_52 AC 6 ms
5,216 KB
testcase_53 AC 7 ms
5,212 KB
testcase_54 AC 6 ms
5,404 KB
testcase_55 AC 24 ms
7,604 KB
testcase_56 AC 6 ms
5,252 KB
testcase_57 AC 6 ms
5,264 KB
testcase_58 AC 6 ms
5,328 KB
testcase_59 AC 6 ms
5,212 KB
testcase_60 AC 6 ms
5,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <atcoder/convolution>
#include <iostream>
#include <algorithm>
#include <vector>

template <class T>
struct Combination {
    int max_n;
    std::vector<T> f, invf;

    explicit Combination(int n)
        : max_n(n), f(n + 1), invf(n + 1) {
        f[0] = 1;
        for (int i = 1; i <= n; ++i) {
            f[i] = f[i - 1] * i;
        }

        invf[max_n] = f[max_n].inv();
        for (int i = max_n - 1; i >= 0; --i) {
            invf[i] = invf[i + 1] * (i + 1);
        }
    }

    T fact(int n) const { return n < 0 ? T(0) : f[n]; }
    T invfact(int n) const { return n < 0 ? T(0) : invf[n]; }
    T perm(int a, int b) const {
        return a < b || b < 0 ? T(0) : f[a] * invf[a - b];
    }
    T binom(int a, int b) const {
        return a < b || b < 0 ? T(0) : f[a] * invf[a - b] * invf[b];
    }
};

using namespace std;
using mint = atcoder::modint998244353;

const Combination<mint> C(300000);

void solve() {
    int n;
    cin >> n;

    vector<mint> is(n, 0), ns(n, 0);
    for (int i = 0; i < n; ++i) {
        char c;
        cin >> c;
        if (c == 'i') {
            is[n - i - 1] = 1;
        } else {
            ns[i] = 1;
        }
    }

    auto fs = atcoder::convolution(is, ns);
    // s[i]='n'とs[n-j-1]='i' => i+j
    // k = i-(n-j-1)-1 = (i+j)-n
    fs.erase(fs.begin(), fs.begin() + n);

    // x -> x+1
    {
        for (int i = 0; i <= n - 2; ++i) fs[i] *= C.fact(i);
        reverse(fs.begin(), fs.end());

        // exp(cx) = sum_i (c^i x^i / i!)
        vector<mint> es(n - 1);
        for (int i = 0; i <= n - 2; ++i) es[i] = C.invfact(i);

        fs = atcoder::convolution(fs, es);
        fs.resize(n - 1);

        reverse(fs.begin(), fs.end());
        for (int i = 0; i <= n - 2; ++i) fs[i] *= C.invfact(i);
    }

    int ans = 0;
    for (auto f : fs) ans ^= f.val();
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0