結果

問題 No.1688 Veterinarian
ユーザー 👑 rin204rin204
提出日時 2022-01-25 17:08:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 958 ms / 3,000 ms
コード長 973 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 87,140 KB
実行使用メモリ 223,396 KB
最終ジャッジ日時 2023-08-22 12:01:45
合計ジャッジ時間 6,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
72,400 KB
testcase_01 AC 107 ms
72,580 KB
testcase_02 AC 111 ms
76,240 KB
testcase_03 AC 104 ms
72,440 KB
testcase_04 AC 106 ms
72,576 KB
testcase_05 AC 104 ms
72,404 KB
testcase_06 AC 146 ms
78,788 KB
testcase_07 AC 105 ms
72,448 KB
testcase_08 AC 958 ms
223,396 KB
testcase_09 AC 916 ms
208,128 KB
testcase_10 AC 333 ms
103,628 KB
testcase_11 AC 215 ms
85,700 KB
testcase_12 AC 104 ms
72,664 KB
testcase_13 AC 234 ms
87,440 KB
testcase_14 AC 114 ms
76,244 KB
testcase_15 AC 448 ms
122,176 KB
testcase_16 AC 108 ms
76,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

@lru_cache(None)
def dfs(a, b, c, n):
    tot = a + b + c
    if n == 0 or tot <= 1:
        return 0, 0, 0
    ret = [0, 0, 0]
    
    div = tot * (tot - 1) // 2
    dif = div
    if a >= 2:
        aa = a * (a - 1) // 2
        dif -= aa
        tmp = dfs(a - 1, b, c, n - 1)
        ret[0] += aa / div
        for i in range(3):
            ret[i] += tmp[i] * aa / div
    if b >= 2:
        bb = b * (b - 1) // 2
        dif -= bb
        tmp = dfs(a, b - 1, c, n - 1)
        ret[1] += bb / div
        for i in range(3):
            ret[i] += tmp[i] * bb / div
    if c >= 2:
        cc = c * (c - 1) // 2
        dif -= cc
        tmp = dfs(a, b, c - 1, n - 1)
        ret[2] += cc / div
        for i in range(3):
            ret[i] += tmp[i] * cc / div
    tmp = dfs(a, b, c, n - 1)
    for i in range(3):
        ret[i] += tmp[i] * dif / div
    return ret
    

a, b, c, n = map(int, input().split())    
print(*dfs(a, b, c, n))
0