結果

問題 No.2137 Stairs of Permutation
ユーザー shobonvipshobonvip
提出日時 2022-11-25 23:17:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,552 KB
実行使用メモリ 217,852 KB
最終ジャッジ日時 2024-04-10 04:22:23
合計ジャッジ時間 11,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 234 ms
214,884 KB
testcase_01 AC 235 ms
215,092 KB
testcase_02 AC 293 ms
217,852 KB
testcase_03 AC 460 ms
217,564 KB
testcase_04 AC 423 ms
217,588 KB
testcase_05 AC 382 ms
217,640 KB
testcase_06 AC 533 ms
217,416 KB
testcase_07 AC 551 ms
217,672 KB
testcase_08 AC 272 ms
217,680 KB
testcase_09 AC 253 ms
217,716 KB
testcase_10 AC 282 ms
217,700 KB
testcase_11 AC 517 ms
217,644 KB
testcase_12 AC 348 ms
217,560 KB
testcase_13 AC 388 ms
217,732 KB
testcase_14 AC 461 ms
217,824 KB
testcase_15 AC 549 ms
217,624 KB
testcase_16 AC 340 ms
217,504 KB
testcase_17 AC 330 ms
217,744 KB
testcase_18 AC 379 ms
217,660 KB
testcase_19 AC 354 ms
217,384 KB
testcase_20 AC 316 ms
217,760 KB
testcase_21 AC 544 ms
217,720 KB
testcase_22 AC 233 ms
215,032 KB
testcase_23 AC 556 ms
217,512 KB
testcase_24 AC 232 ms
215,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
N = 10**7 + 5
fact = [1]*(N+1)
factinv = [1]*(N+1)

for i in range(2, N+1):
	fact[i] = fact[i-1] * i % mod

factinv[-1] = pow(fact[-1], mod-2, mod)
for i in range(N-1, 1, -1):
	factinv[i] = factinv[i+1] * (i+1) % mod

def cmb(a, b):
	if (a < b) or (b < 0):
		return 0
	return fact[a] * factinv[b] % mod * factinv[a-b] % mod

n = int(input())

h20, h21 = 0, 2
h30, h31, h32 = 0, 0, 6

# h30^3 + 3h20^2 + h10 の累積和
ans = 0

for i in range(1, n+1):
	ans += (h30 + 3 * h20 + fact[i-1]) % mod * factinv[i] % mod
	ans %= mod
	h20, h21 = h21, (h21 * (2*i+1) % mod - h20 * i % mod * i) % mod
	h30, h31, h32 = h31, h32, (h32 * (3+3*i) % mod - h31 * (3*i*i%mod+3*i+1) % mod + h30 * i % mod * i % mod * i % mod) % mod

print(ans * fact[n] % mod)
0