結果

問題 No.2409 Strange Werewolves
ユーザー sotanishysotanishy
提出日時 2023-08-11 22:13:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2024-04-29 13:11:57
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,968 KB
testcase_01 AC 50 ms
57,984 KB
testcase_02 AC 42 ms
51,712 KB
testcase_03 AC 63 ms
67,072 KB
testcase_04 AC 64 ms
67,328 KB
testcase_05 AC 55 ms
62,592 KB
testcase_06 AC 64 ms
67,328 KB
testcase_07 AC 68 ms
67,328 KB
testcase_08 AC 55 ms
63,360 KB
testcase_09 AC 56 ms
63,616 KB
testcase_10 AC 50 ms
60,800 KB
testcase_11 AC 48 ms
58,240 KB
testcase_12 AC 52 ms
60,800 KB
testcase_13 AC 55 ms
62,976 KB
testcase_14 AC 58 ms
64,000 KB
testcase_15 AC 57 ms
63,616 KB
testcase_16 AC 54 ms
62,336 KB
testcase_17 AC 49 ms
58,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline


def comb_preprocess(n):
    fact = [1] * (n+1)
    fact_inv = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = i * fact[i-1] % mod
    fact_inv[n] = pow(fact[n], mod-2, mod)
    for i in range(1, n+1)[::-1]:
        fact_inv[i-1] = i * fact_inv[i] % mod

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

    return fact, fact_inv, comb


mod = 998244353
X, Y, Z, W = map(int, input().split())
human = X-Z
wolf = Y-W
fact, fact_inv, comb = comb_preprocess(X+Y)
ans = comb(X, human) * comb(Y, wolf) * (human if Z ==
                                        0 else wolf) * fact[human+wolf-1] % mod
print(ans)
0