結果

問題 No.1688 Veterinarian
ユーザー 👑 rin204rin204
提出日時 2022-01-25 17:08:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 791 ms / 3,000 ms
コード長 973 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 218,768 KB
最終ジャッジ日時 2024-05-09 17:43:32
合計ジャッジ時間 4,010 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,912 KB
testcase_01 AC 42 ms
54,912 KB
testcase_02 AC 51 ms
62,208 KB
testcase_03 AC 42 ms
54,656 KB
testcase_04 AC 42 ms
54,528 KB
testcase_05 AC 41 ms
54,912 KB
testcase_06 AC 109 ms
77,440 KB
testcase_07 AC 45 ms
55,040 KB
testcase_08 AC 791 ms
218,768 KB
testcase_09 AC 701 ms
204,100 KB
testcase_10 AC 244 ms
98,808 KB
testcase_11 AC 139 ms
82,456 KB
testcase_12 AC 42 ms
54,656 KB
testcase_13 AC 166 ms
81,592 KB
testcase_14 AC 50 ms
62,720 KB
testcase_15 AC 323 ms
116,472 KB
testcase_16 AC 44 ms
61,312 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