結果

問題 No.2033 Chromatic Duel
ユーザー qwewe
提出日時 2025-04-24 12:20:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,556 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,756 KB
実行使用メモリ 69,336 KB
最終ジャッジ日時 2025-04-24 12:22:10
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 3
other AC * 7 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    N, B, W = map(int, sys.stdin.readline().split())
    K = 3 * B - N + W
    if K < 0 or (K % 1 != 0):
        print(0)
        return
    if B == 0:
        if W == 0:
            print(1)
        else:
            print(0)
        return
    if B == 1:
        cnt = 0
        for x in range(1, N+1):
            covered = 1
            if x > 1:
                covered += 1
            if x < N:
                covered += 1
            if N - covered == W:
                cnt += 1
        print(cnt % MOD)
        return

    max_fact = 2 * 10**5 + 10
    fact = [1] * (max_fact)
    for i in range(1, max_fact):
        fact[i] = fact[i-1] * i % MOD
    inv_fact = [1] * (max_fact)
    inv_fact[max_fact-1] = pow(fact[max_fact-1], MOD-2, MOD)
    for i in range(max_fact-2, -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

    ans = 0
    for a in range(0, B):
        if 2*a > K:
            break
        b = K - 2*a
        if b < 0:
            continue
        if a + b > B-1:
            continue
        c = (B-1) - a - b
        if c < 0:
            continue
        sum_d_min = a + 2*b + 3*c
        S_min = sum_d_min + 1
        if S_min > N:
            continue
        ways_comb = comb(B-1, a) * comb(B-1 -a, b) % MOD
        ans = (ans + ways_comb * (N - S_min + 1)) % MOD
    print(ans % MOD)

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