結果

問題 No.1688 Veterinarian
ユーザー nephrologistnephrologist
提出日時 2021-09-25 12:31:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,239 ms / 3,000 ms
コード長 765 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 285,816 KB
最終ジャッジ日時 2023-09-18 22:59:53
合計ジャッジ時間 6,661 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
72,560 KB
testcase_01 AC 105 ms
76,088 KB
testcase_02 AC 132 ms
78,512 KB
testcase_03 AC 101 ms
72,492 KB
testcase_04 AC 102 ms
72,504 KB
testcase_05 AC 102 ms
72,372 KB
testcase_06 AC 280 ms
108,216 KB
testcase_07 AC 100 ms
72,508 KB
testcase_08 AC 729 ms
185,700 KB
testcase_09 AC 823 ms
202,804 KB
testcase_10 AC 469 ms
135,204 KB
testcase_11 AC 218 ms
93,132 KB
testcase_12 AC 103 ms
72,392 KB
testcase_13 AC 260 ms
98,032 KB
testcase_14 AC 108 ms
76,864 KB
testcase_15 AC 1,239 ms
285,816 KB
testcase_16 AC 113 ms
77,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

a, b, c, n = map(int, input().split())


def probability(a, goukei):
    return (a * (a - 1)) / (goukei * (goukei - 1))


@lru_cache(None)
def calc(a, b, c, n):
    goukei = a + b + c
    if goukei <= 1:
        return 0
    if a == 0:
        return 0
    if (b + c) == 0:
        return 1

    if n == 1:
        return probability(a, goukei)

    proba = probability(a, goukei)
    probb = probability(b, goukei)
    probc = probability(c, goukei)
    return (
        proba * (1 + calc(a - 1, b, c, n - 1))
        + probb * (calc(a, b - 1, c, n - 1))
        + probc * (calc(a, b, c - 1, n - 1))
        + (1 - proba - probb - probc) * (calc(a, b, c, n - 1))
    )


print(calc(a, b, c, n), calc(b, c, a, n), calc(c, a, b, n))
0