結果

問題 No.2245 Second Smallest
ユーザー shobonvipshobonvip
提出日時 2023-01-14 01:28:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 93,692 KB
最終ジャッジ日時 2023-08-30 03:27:53
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
91,404 KB
testcase_01 AC 98 ms
91,636 KB
testcase_02 AC 98 ms
91,596 KB
testcase_03 AC 99 ms
91,420 KB
testcase_04 AC 97 ms
91,596 KB
testcase_05 AC 179 ms
93,420 KB
testcase_06 AC 177 ms
93,228 KB
testcase_07 AC 99 ms
91,936 KB
testcase_08 AC 98 ms
91,728 KB
testcase_09 AC 179 ms
93,688 KB
testcase_10 AC 154 ms
93,008 KB
testcase_11 AC 149 ms
92,768 KB
testcase_12 AC 142 ms
92,936 KB
testcase_13 AC 124 ms
92,296 KB
testcase_14 AC 137 ms
93,048 KB
testcase_15 AC 149 ms
93,344 KB
testcase_16 AC 124 ms
92,852 KB
testcase_17 AC 132 ms
92,788 KB
testcase_18 AC 140 ms
93,000 KB
testcase_19 AC 150 ms
93,260 KB
testcase_20 AC 141 ms
92,804 KB
testcase_21 AC 132 ms
92,784 KB
testcase_22 AC 148 ms
93,144 KB
testcase_23 AC 120 ms
92,436 KB
testcase_24 AC 151 ms
93,120 KB
testcase_25 AC 126 ms
92,212 KB
testcase_26 AC 99 ms
91,864 KB
testcase_27 AC 167 ms
93,692 KB
testcase_28 AC 126 ms
92,924 KB
testcase_29 AC 120 ms
93,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# O(min(H,W) log M + K)

mod = 998244353
N = 10 ** 6
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

h,w,k = map(int,input().split())
l = [0] * (min(h,w) + 2) # / factinv[h*w-a]

for a in range(1, min(h,w)+1):
	l[a] = cmb(h,a) * cmb(w,a) % mod * fact[a] % mod

#print(l)

tmp = 1
for i in range(h*w+k, h*w-2, -1):
	tmp *= i
	tmp %= mod

ans = 0
for a in range(2, min(h,w)+2):
	ans += (l[a-1] - l[a] * pow(h*w-a+1, mod-2, mod)) * a % mod * (h*w-a+1) % mod * factinv[a] % mod * fact[a+k-1] % mod * pow(tmp, mod-2, mod) % mod
	tmp *= h*w-a
	tmp %= mod

print(ans % mod)
0