結果

問題 No.2033 Chromatic Duel
ユーザー gew1fw
提出日時 2025-06-12 17:00:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 62,848 KB
最終ジャッジ日時 2025-06-12 17:00:25
合計ジャッジ時間 3,495 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 7 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    B = int(input[1])
    W = int(input[2])
    
    if B + W > N:
        print(0)
        return
    
    R = N - W
    numerator = 3 * B - R
    if numerator < 0 or numerator % 2 != 0:
        print(0)
        return
    
    k = numerator // 2
    if k < 0 or k > B - 1:
        print(0)
        return
    
    m = B - k
    n = N - m - 1
    if n < 0 or m < 0 or m > n:
        print(0)
        return
    
    # Precompute fact and inv_fact up to max needed value
    max_n = max(n, B)
    fact = [1] * (max_n + 1)
    for i in range(1, max_n + 1):
        fact[i] = fact[i-1] * i % MOD
    inv_fact = [1] * (max_n + 1)
    inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)
    for i in range(max_n-1, -1, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
    
    def comb(n, k):
        if n < 0 or k < 0 or k > n:
            return 0
        return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD
    
    res = comb(n, m)
    print(res)

if __name__ == '__main__':
    main()
0