結果

問題 No.2409 Strange Werewolves
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-11-25 17:03:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 193,016 KB
最終ジャッジ日時 2023-11-25 17:03:07
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,740 KB
testcase_01 AC 49 ms
63,828 KB
testcase_02 AC 44 ms
55,740 KB
testcase_03 AC 185 ms
193,016 KB
testcase_04 AC 186 ms
193,016 KB
testcase_05 AC 119 ms
126,932 KB
testcase_06 AC 210 ms
193,016 KB
testcase_07 AC 188 ms
193,016 KB
testcase_08 AC 126 ms
134,692 KB
testcase_09 AC 135 ms
143,544 KB
testcase_10 AC 88 ms
98,260 KB
testcase_11 AC 56 ms
70,100 KB
testcase_12 AC 90 ms
102,356 KB
testcase_13 AC 126 ms
134,564 KB
testcase_14 AC 139 ms
144,056 KB
testcase_15 AC 143 ms
143,416 KB
testcase_16 AC 118 ms
126,548 KB
testcase_17 AC 56 ms
71,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline
class combination():
    
    def __init__(self,N,p):
        
        
        self.fact = [1, 1]  # fact[n] = (n! mod p)
        self.factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        self.inv = [0, 1]  # factinv 計算用
        self.p = p
        
        for i in range(2, N + 1):
            self.fact.append((self.fact[-1] * i) % p)
            self.inv.append((-self.inv[p % i] * (p // i)) % p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % p)
        

    def cmb(self,n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.p
        
        
X,Y,Z,W = map(int,input().split())
mod = 998244353
C = combination(X+Y,mod)
if W==0:
    X,Y = Y,X
    W,Z = Z,W

dx = X-1
dy = Y-W
print(C.cmb(dx+dy,dx)*C.fact[dy]*C.fact[dx+1]*C.cmb(X,dx+1)*C.cmb(Y,dy)%mod)
0