結果

問題 No.2135 C5
ユーザー shobonvipshobonvip
提出日時 2022-10-21 00:26:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 923 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 78,160 KB
最終ジャッジ日時 2023-09-13 04:26:20
合計ジャッジ時間 16,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 72 ms
71,176 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 72 ms
71,196 KB
testcase_12 AC 73 ms
71,284 KB
testcase_13 AC 71 ms
71,212 KB
testcase_14 AC 71 ms
71,200 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 515 ms
77,912 KB
testcase_26 AC 157 ms
77,192 KB
testcase_27 AC 152 ms
77,584 KB
testcase_28 AC 432 ms
77,864 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 514 ms
77,940 KB
testcase_34 AC 514 ms
77,992 KB
testcase_35 AC 72 ms
71,256 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 76 ms
71,004 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 190 ms
77,196 KB
testcase_43 AC 94 ms
76,564 KB
testcase_44 AC 73 ms
71,420 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 515 ms
78,116 KB
testcase_49 WA -
testcase_50 AC 513 ms
77,748 KB
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
N, M = map(int,input().split())
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

inv2 = pow(2, mod-2, mod)

dp = [[0] * (N+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(N+1):
	for j in range(N+1):
		# パス
		if i+1 <= N:
			dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod
		for k in range(2, min(N-i, N-j+1)+1):
			dp[i+k][j+k-1] = (dp[i+k][j+k-1] + cmb(N-i-1, k-1) * dp[i][j] % mod * fact[k] % mod * inv2) % mod
		# 閉路
		for k in range(5, min(N-i, N-j)+1):
			dp[i+k][j+k] = (dp[i+k][j+k] + cmb(N-i-1, k-1) * dp[i][j] % mod * fact[k-1] % mod * inv2) % mod

if M < N*(N+1)//2 - N:
	print(0)
else:
	print(sum(dp[N][N*(N+1)//2-M:]) % mod)
0