結果

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

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read
    N, B, W = map(int, input().split())
    
    D = N - W
    if (D - B) < 0 or (D - B) % 2 != 0:
        print(0)
        return
    
    k = (D - B) // 2
    if B + 4 * k - 2 > N:
        print(0)
        return
    
    S = N - (B + 4 * k - 2)
    if S < 0:
        print(0)
        return
    
    # Precompute factorial and inverse factorial up to max needed
    max_needed = max(B + k, S + k)
    if max_needed > 2 * 10**5:
        print(0)
        return
    
    # Precompute factorial and inverse factorial
    max_fact = 2 * 10**5 + 10
    fact = [1] * (max_fact + 1)
    for i in range(1, max_fact + 1):
        fact[i] = fact[i-1] * i % MOD
    
    inv_fact = [1] * (max_fact + 1)
    inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD)
    for i in range(max_fact -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
    
    c1 = comb(B-1, k-1)
    c2 = comb(S + k, k)
    print((c1 * c2) % MOD)

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