結果

問題 No.2391 SAN 値チェック
ユーザー 👑 tatyamtatyam
提出日時 2023-07-13 07:41:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,882 bytes
コンパイル時間 3,094 ms
コンパイル使用メモリ 246,152 KB
実行使用メモリ 7,432 KB
最終ジャッジ日時 2023-10-12 21:07:48
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,220 KB
testcase_01 AC 8 ms
7,264 KB
testcase_02 AC 8 ms
7,432 KB
testcase_03 AC 37 ms
7,256 KB
testcase_04 AC 23 ms
7,236 KB
testcase_05 AC 32 ms
7,328 KB
testcase_06 AC 20 ms
7,328 KB
testcase_07 AC 19 ms
7,300 KB
testcase_08 AC 15 ms
7,252 KB
testcase_09 AC 19 ms
7,344 KB
testcase_10 AC 28 ms
7,200 KB
testcase_11 AC 10 ms
7,256 KB
testcase_12 AC 44 ms
7,220 KB
testcase_13 AC 45 ms
7,344 KB
testcase_14 AC 46 ms
7,248 KB
testcase_15 AC 45 ms
7,236 KB
testcase_16 AC 45 ms
7,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;

using mint = atcoder::static_modint<998244353>;
istream& operator>>(istream& in, mint& x) { long long a; in >> a; x = a; return in; }
ostream& operator<<(ostream& out, mint x) { return out << x.val(); }
mint operator""_M(unsigned long long x) { return x; }

constexpr uint32_t fact_mx = min<uint32_t>(5e5, mint::mod() - 1);
mint fac[fact_mx + 1], inv[fact_mx + 1];
struct factorial {
    factorial() {
        fac[0] = 1;
        for(uint32_t i = 1; i <= fact_mx; i++) fac[i] = fac[i - 1] * mint::raw(i);
        inv[fact_mx] = fac[fact_mx].inv();
        for(uint32_t i = fact_mx; i; i--) inv[i - 1] = inv[i] * mint::raw(i);
    }
} factorial;
mint inverse(long long n) { return inv[n] * fac[n - 1]; }
mint perm(long long n, long long r) {
    if(n < r || r < 0) return 0;
    if(n > fact_mx) [[unlikely]] {
        mint ans = 1, x = n;
        while(r--) ans *= x--;
        return ans;
    }
    return fac[n] * inv[n - r];
}
mint comb(long long n, long long r) {
    if(n < r || r < 0) return 0;
    r = min(r, n - r);
    const mint ans = perm(n, r);
    return ans * inv[r];
}
template<class... T> mint comb(long long n, T... rs) {
    if(n < 0) return 0;
    mint ans = fac[n];
    long long rn = n;
    for(long long r : {rs...}) {
        if(r < 0) return 0;
        ans *= inv[r];
        rn -= r;
    }
    if(rn < 0) return 0;
    return ans * inv[rn];
}
mint Mcomb(long long n, long long r){ return comb(n + r - 1, r); } // r balls into n boxes

/*
 k 回振ったときの総和の確率密度分布 f_k(x) = f_1(x) の k 回畳み込み
 区分 k - 1 次関数 区分の長さはそれぞれ 1
 モーメント母関数ってやつを考えれば良いですか
 M(f_1) = (e^t - 1) / t
 p[k][x] := k 回振ったときに総和が x 以下になる確率 のテーブルを求めてみよう
 https://oeis.org/A008292
 https://en.wikipedia.org/wiki/Eulerian_number
 あったあ
 https://en.wikipedia.org/wiki/Eulerian_number を T(n,k) として
 sum(T(n,k)/n! for n ≥ 0, 0 ≤ k < N) が答え
 sum(T(n,0)/n! for n ≥ 0) =         e
 sum(T(n,1)/n! for n ≥ 0) =      -2 e   + e^2
 sum(T(n,2)/n! for n ≥ 0) * 2! =  3 e  -6 e^2   +2 e^3
 sum(T(n,3)/n! for n ≥ 0) * 3! = -4 e +24 e^2  -24 e^3   +6 e^4
 sum(T(n,4)/n! for n ≥ 0) * 4! =  5 e -80 e^2 +180 e^3 -120 e^4 +24 e^5
 
 縦に見て OEIS に入れたりすると、sum(T(i,n)/i! for i ≥ 0) の e^k の係数は
  k^{n + 1 - k} / (n + 1 - k)! * (n + 1) / k * (-1)^{n+k+1}
 
 Sum[k^(n + 1 - k) / (n + 1 - k)! * (n + 1) / k * (-1)^(n+k+1), {n, k-1, N-1}]
 == ((-1)^(k + N + 1) k^(N - k) (k - N - 1))/((-k + N + 1)!)
 
 できたわ
 */
int main() {
    int N;
    cin >> N;
    cout << "0\n";
    for(int k = 1; k <= N; k++) {
        const mint ans = mint{-k}.pow(N - k) * inv[N - k];
        cout << ans.val() << '\n';
    }
}
0