結果

問題 No.2527 H and W
ユーザー rlangevinrlangevin
提出日時 2023-11-03 21:35:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 714 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 93,260 KB
最終ジャッジ日時 2023-11-03 21:35:29
合計ジャッジ時間 4,040 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
90,856 KB
testcase_01 AC 81 ms
90,856 KB
testcase_02 AC 100 ms
91,192 KB
testcase_03 AC 79 ms
90,856 KB
testcase_04 AC 79 ms
90,856 KB
testcase_05 AC 80 ms
90,856 KB
testcase_06 AC 85 ms
91,192 KB
testcase_07 AC 79 ms
90,856 KB
testcase_08 AC 107 ms
91,176 KB
testcase_09 AC 80 ms
90,856 KB
testcase_10 AC 80 ms
90,856 KB
testcase_11 AC 84 ms
91,176 KB
testcase_12 AC 92 ms
93,260 KB
testcase_13 AC 92 ms
93,260 KB
testcase_14 AC 104 ms
93,260 KB
testcase_15 AC 84 ms
91,176 KB
testcase_16 AC 102 ms
91,192 KB
testcase_17 AC 101 ms
93,260 KB
testcase_18 AC 101 ms
93,260 KB
testcase_19 AC 98 ms
93,260 KB
testcase_20 AC 102 ms
93,260 KB
testcase_21 AC 104 ms
93,260 KB
testcase_22 AC 103 ms
93,260 KB
testcase_23 AC 104 ms
93,260 KB
testcase_24 AC 92 ms
91,176 KB
testcase_25 AC 81 ms
91,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
n = 2 * 10 ** 6 + 5
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod


H, W, K = map(int, input().split())
K = H * W - K
ans = 0
for h in range(H):
    if K - h * W < 0:
        break
    if (K - h * W) % (H - h) != 0:
        continue
    w = (K - h * W) // (H - h)
    ans += comb(H, h) * comb(W, w)
    ans %= mod
    
if K == H * W:
    ans += pow(2, W, mod)
    ans %= mod
    
print(ans)
0