結果

問題 No.2409 Strange Werewolves
ユーザー lloyz
提出日時 2023-08-20 00:02:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 73,664 KB
最終ジャッジ日時 2024-11-29 22:13:04
合計ジャッジ時間 1,875 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

x, y, z, w = map(int, input().split())
mod = 998244353

dif = x + y - z - w - 1
fact = [1] * (dif + 1)
inv = [1] * (dif + 1)
finv = [1] * (dif + 1)
for i in range(2, dif + 1):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod
def comb(x, y):
    return fact[x] * finv[y] % mod * finv[x - y] % mod

ans = 1
for i in range(x, z, -1):
    ans *= i
    ans %= mod
for i in range(y, w, -1):
    ans *= i
    ans %= mod
if z == 0:
    ans *= comb(dif, y - w)
else:
    ans *= comb(dif, x - z)
ans %= mod
print(ans)
0