結果

問題 No.2135 C5
ユーザー shobonvipshobonvip
提出日時 2022-10-21 00:27:34
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 923 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 78,144 KB
最終ジャッジ日時 2023-09-13 11:47:42
合計ジャッジ時間 17,580 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 71 ms
71,220 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 70 ms
71,388 KB
testcase_07 WA -
testcase_08 AC 70 ms
71,316 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 70 ms
71,164 KB
testcase_12 AC 71 ms
71,316 KB
testcase_13 AC 70 ms
71,240 KB
testcase_14 AC 70 ms
71,248 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 512 ms
77,884 KB
testcase_26 AC 155 ms
77,304 KB
testcase_27 AC 149 ms
77,392 KB
testcase_28 AC 432 ms
77,872 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 515 ms
77,860 KB
testcase_34 AC 515 ms
77,892 KB
testcase_35 AC 74 ms
71,252 KB
testcase_36 WA -
testcase_37 AC 71 ms
71,264 KB
testcase_38 AC 70 ms
71,120 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 188 ms
77,392 KB
testcase_43 AC 92 ms
76,600 KB
testcase_44 AC 73 ms
71,260 KB
testcase_45 AC 302 ms
77,664 KB
testcase_46 AC 91 ms
76,544 KB
testcase_47 AC 167 ms
77,152 KB
testcase_48 AC 512 ms
77,808 KB
testcase_49 AC 517 ms
77,784 KB
testcase_50 AC 512 ms
78,128 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