結果

問題 No.1688 Veterinarian
コンテスト
ユーザー norioc
提出日時 2026-01-22 01:40:30
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 1,253 ms / 3,000 ms
コード長 673 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,968 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 218,676 KB
最終ジャッジ日時 2026-01-22 01:40:40
合計ジャッジ時間 7,196 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import comb
from functools import cache

@cache
def f(a, b, c, n) -> float:
    if n == 0: return 0
    if a+b+c < 2: return 0

    deno = comb(a+b+c, 2)
    sp = 0
    res = 0
    if a >= 2:
        p = comb(a, 2) / deno
        res += p * (f(a-1, b, c, n-1) + 1)
        sp += p

    if b >= 2:
        p = comb(b, 2) / deno
        res += p * f(a, b-1, c, n-1)
        sp += p

    if c >= 2:
        p = comb(c, 2) / deno
        res += p * f(a, b, c-1, n-1)
        sp += p

    rest_p = 1 - sp
    res += rest_p * f(a, b, c, n-1)

    return res


A, B, C, N = map(int, input().split())

a = f(A, B, C, N)
b = f(B, A, C, N)
c = f(C, A, B, N)
print(a, b, c)
0