結果

問題 No.2391 SAN 値チェック
ユーザー qwewe
提出日時 2025-04-24 12:26:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,013 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,444 KB
実行使用メモリ 81,292 KB
最終ジャッジ日時 2025-04-24 12:26:44
合計ジャッジ時間 2,486 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    
    max_n = N
    fact = [1] * (max_n + 1)
    for i in range(1, max_n + 1):
        fact[i] = fact[i-1] * i % MOD
    
    inv_fact = [1] * (max_n + 1)
    inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)
    for i in range(max_n - 1, -1, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
    
    results = [0] * (N + 1)
    for i in range(N + 1):
        if i == 0:
            results[i] = 0
        else:
            k = N - i
            sign = 1 if k % 2 == 0 else MOD - 1
            # Compute C(N-1, i-1) = fact[N-1] * inv_fact[i-1] * inv_fact[N-i] % MOD
            comb = fact[N-1] * inv_fact[i-1] % MOD
            comb = comb * inv_fact[N - i] % MOD
            denominator_inv = inv_fact[k]
            res = sign * comb % MOD
            res = res * denominator_inv % MOD
            results[i] = res
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()
0