結果

問題 No.2409 Strange Werewolves
ユーザー ShirotsumeShirotsume
提出日時 2023-08-11 21:32:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 85,376 KB
最終ジャッジ日時 2024-04-29 12:22:35
合計ジャッジ時間 4,659 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
85,376 KB
testcase_01 AC 205 ms
84,736 KB
testcase_02 AC 205 ms
85,120 KB
testcase_03 AC 202 ms
84,736 KB
testcase_04 AC 200 ms
85,248 KB
testcase_05 AC 202 ms
85,120 KB
testcase_06 AC 203 ms
84,864 KB
testcase_07 AC 194 ms
84,864 KB
testcase_08 AC 192 ms
84,864 KB
testcase_09 AC 194 ms
85,248 KB
testcase_10 AC 201 ms
85,120 KB
testcase_11 AC 201 ms
85,120 KB
testcase_12 AC 191 ms
84,736 KB
testcase_13 AC 191 ms
85,120 KB
testcase_14 AC 190 ms
84,992 KB
testcase_15 AC 195 ms
84,992 KB
testcase_16 AC 204 ms
84,992 KB
testcase_17 AC 197 ms
84,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

class Combinatorics():
    def __init__(self, mod, maxi):
        self.mod = mod
        self.maxi = maxi
        self.facs = [1] * (maxi + 1)
        self.factinvs = [1] * (maxi + 1)
        self.invs = [1] * (maxi + 1)
        for i in range(2, self.maxi + 1):
            self.facs[i] = ((self.facs[i-1] * i) % self.mod)
            self.invs[i] = (-self.invs[self.mod % i] * (self.mod // i)) % self.mod
            self.factinvs[i] = (self.factinvs[i-1] * self.invs[i]) % self.mod
            
    def choose(self, n, k) -> int:
        if k < 0 or k > n: return 0
        if k == 0 or k == n: return 1
        k = min(k, n - k)
        return (((self.facs[n] * self.factinvs[k]) % self.mod) * self.factinvs[n-k]) % self.mod
    
    def perm(self, n, k) -> int:
        return (self.choose(n, k) * self.facs[k]) % self.mod

    def homop(self, n, k) -> int:
        if n == k == 0:
            return 1
        return self.choose(n + k - 1, k)

x, y, z, w = mi()

if z == 0:
    w, z = z, w
    x, y = y, x

counth = x - z
countw = y - 1
C = Combinatorics(mod, 10 ** 6)
print(C.choose(counth + countw, countw) * C.facs[y] % mod * C.perm(x, counth) % mod)

0