結果
問題 | No.2137 Stairs of Permutation |
ユーザー |
![]() |
提出日時 | 2025-03-26 16:00:03 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 692 bytes |
コンパイル時間 | 394 ms |
コンパイル使用メモリ | 82,616 KB |
実行使用メモリ | 176,912 KB |
最終ジャッジ日時 | 2025-03-26 16:01:04 |
合計ジャッジ時間 | 5,570 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 1 TLE * 1 -- * 21 |
ソースコード
MOD = 998244353n = int(input())if n == 0:print(0)exit()# Precompute factorial modulo MODfact = [1] * (n + 1)for i in range(1, n + 1):fact[i] = fact[i-1] * i % MOD# Precompute inverses of 1..n modulo MODinv = [0] * (n + 1)for i in range(1, n + 1):inv[i] = pow(i, MOD-2, MOD)e0 = 1e1 = 0e2 = 0e3 = 0for i in range(1, n + 1):inv_i = inv[i]# Update e3e3 = (e3 + e2 * inv_i) % MOD# Update e2e2 = (e2 + e1 * inv_i) % MOD# Update e1e1 = (e1 + e0 * inv_i) % MOD# Compute the sum with the correct coefficientssum_val = (e1 + 6 * e2 + 6 * e3) % MOD# Multiply by factorial[n] mod MODans = sum_val * fact[n] % MODprint(ans)