結果

問題 No.2033 Chromatic Duel
ユーザー qwewe
提出日時 2025-04-24 12:21:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 887 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 54,196 KB
最終ジャッジ日時 2025-04-24 12:23:32
合計ジャッジ時間 3,324 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 8 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    N, B, W = map(int, sys.stdin.readline().split())
    
    if W != N - 3 * B:
        print(0)
        return
    
    if N < 3 * B:
        print(0)
        return
    
    # Compute C(n, k) mod MOD where n = N - 2B, k = B
    n = N - 2 * B
    k = B
    
    if k < 0 or k > n:
        print(0)
        return
    
    # Precompute factorial and inverse factorial modulo MOD up to n
    max_n = n
    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
    
    # Compute combination
    comb = fact[n] * inv_fact[k] % MOD
    comb = comb * inv_fact[n - k] % MOD
    print(comb)

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