結果
| 問題 |
No.2137 Stairs of Permutation
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 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 = 998244353
n = int(input())
if n == 0:
print(0)
exit()
# Precompute factorial modulo MOD
fact = [1] * (n + 1)
for i in range(1, n + 1):
fact[i] = fact[i-1] * i % MOD
# Precompute inverses of 1..n modulo MOD
inv = [0] * (n + 1)
for i in range(1, n + 1):
inv[i] = pow(i, MOD-2, MOD)
e0 = 1
e1 = 0
e2 = 0
e3 = 0
for i in range(1, n + 1):
inv_i = inv[i]
# Update e3
e3 = (e3 + e2 * inv_i) % MOD
# Update e2
e2 = (e2 + e1 * inv_i) % MOD
# Update e1
e1 = (e1 + e0 * inv_i) % MOD
# Compute the sum with the correct coefficients
sum_val = (e1 + 6 * e2 + 6 * e3) % MOD
# Multiply by factorial[n] mod MOD
ans = sum_val * fact[n] % MOD
print(ans)
lam6er