結果

問題 No.2409 Strange Werewolves
ユーザー rulerruler
提出日時 2023-08-14 15:24:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 726 ms / 2,000 ms
コード長 2,332 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 134,912 KB
最終ジャッジ日時 2024-05-02 03:29:17
合計ジャッジ時間 14,472 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 718 ms
134,784 KB
testcase_01 AC 707 ms
134,784 KB
testcase_02 AC 709 ms
134,776 KB
testcase_03 AC 707 ms
134,784 KB
testcase_04 AC 724 ms
134,784 KB
testcase_05 AC 703 ms
134,784 KB
testcase_06 AC 719 ms
134,908 KB
testcase_07 AC 707 ms
134,776 KB
testcase_08 AC 709 ms
134,784 KB
testcase_09 AC 702 ms
134,912 KB
testcase_10 AC 704 ms
134,864 KB
testcase_11 AC 705 ms
134,780 KB
testcase_12 AC 716 ms
134,780 KB
testcase_13 AC 712 ms
134,912 KB
testcase_14 AC 715 ms
134,784 KB
testcase_15 AC 714 ms
134,912 KB
testcase_16 AC 700 ms
134,860 KB
testcase_17 AC 726 ms
134,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

V = sys.version_info
_39 = False
_310 = False
_311 = False
if V.major == 3:
    _39 = V.minor >= 9
    _310 = V.minor >= 10
    _311 = V.minor >= 11

if _39:
    li = list
    tup = tuple
    dic = dict
    st = set
    ty = type
else:
    from typing import (
        List,
        Tuple,
        Type,
        Dict,
        Set,
    )

    li = List
    tup = Tuple
    dic = Dict
    st = Set
    ty = Type

from sys import stdin

read = stdin.buffer.read
rl = stdin.buffer.readline
rb = lambda: rl().split()
rls = stdin.buffer.readlines

from typing import Iterable


def prints(
    a: Iterable[object],
    sep: str = "\n",
) -> None:
    print(sep.join(map(str, a)))


def cumprod(m: int, a: li[int]) -> None:
    n = len(a)
    for i in range(1, n):
        a[i] *= a[i - 1]
        a[i] %= m


def fact(m: int, n: int) -> li[int]:
    f = list(range(n))
    f[0] = 1
    cumprod(m, f)
    return f


def tables(
    m: int, n: int
) -> tup[(li[int],) * 3]:
    f = fact(m, n)
    fi = [0] * n
    iv = [0] * n
    fi[-1] = pow(f[-1], -1, m)
    for i in range(1, n)[::-1]:
        fi[i - 1] = fi[i] * i % m
        iv[i] = fi[i] * f[i - 1] % m
    return f, fi, iv


class Comb:
    m: int
    f: li[int]
    fi: li[int]
    inv: li[int]

    def __init__(
        self, m: int, n: int
    ) -> None:
        self.m = m
        self.f, self.fi, self.inv = tables(
            m, n
        )

    def p(self, n: int, k: int) -> int:
        if k < 0 or n < k:
            return 0
        x = self.f[n] * self.fi[n - k]
        return x % self.m

    def c(self, n: int, k: int) -> int:
        x = self.p(n, k) * self.fi[k]
        return x % self.m

    def h(self, n: int, k: int) -> int:
        return self.c(n - 1 + k, k)

    def ip(self, n: int, k: int) -> int:
        assert 0 <= k <= n
        x = self.fi[n] * self.f[n - k]
        return x % self.m

    def ic(self, n: int, k: int) -> int:
        x = self.ip(n, k) * self.f[k]
        return x % self.m


def solve() -> None:
    mod = 998_244_353
    x, y, z, w = map(int, rb())
    f = Comb(mod, 1 << 20)
    z = max(z, 1)
    w = max(w, 1)
    v = f.f[x + y - z - w]
    v *= f.c(x, z)
    v %= mod
    v *= f.c(y, w)
    v %= mod
    print(v)


def main() -> None:
    t = 1
    # t = int(rl())
    for _ in range(t):
        solve()


main()
0