목차

Balls of Three Colors

ps
링크acmicpc.net/…
출처BOJ
문제 번호32914
문제명Balls of Three Colors
레벨플래티넘 4
분류

조합론

시간복잡도O(n)
인풋사이즈n<=10^5
사용한 언어Python 3.13
제출기록42728KB / 960ms
최고기록960ms
해결날짜2026/03/27

풀이

코드

"""Solution code for "BOJ 32914. Balls of Three Colors".

- Problem link: https://www.acmicpc.net/problem/32914
- Solution link: http://www.teferi.net/ps/problems/boj/32914

Tags: [combinatoric]
"""

from teflib import modcomb


MOD = 998_244_353


def main():
    modcomb.set_mod(MOD)

    r, g, b = [int(x) for x in input().split()]

    answer = 0
    for i in range(max(2, r + g - b), (min(r, g) + 1) * 2):
        b_count = modcomb.comb(i + 1, b - (r + g - i))
        ii = i // 2 - 1
        if i % 2 == 0:
            rg_count = modcomb.comb(r - 1, ii) * modcomb.comb(g - 1, ii) * 2
        else:
            rg_count = (
                modcomb.comb(r - 1, ii) * modcomb.comb(g - 1, ii + 1)
            ) + modcomb.comb(r - 1, ii + 1) * modcomb.comb(g - 1, ii)
        answer += rg_count * b_count

    print(answer % MOD)


if __name__ == '__main__':
    main()