結果

問題 No.1688 Veterinarian
ユーザー ygd.ygd.
提出日時 2021-09-24 21:59:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,881 ms / 3,000 ms
コード長 1,084 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 244,144 KB
最終ジャッジ日時 2023-09-18 21:19:44
合計ジャッジ時間 14,238 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
72,160 KB
testcase_01 AC 130 ms
77,972 KB
testcase_02 AC 163 ms
79,972 KB
testcase_03 AC 113 ms
72,368 KB
testcase_04 AC 114 ms
72,152 KB
testcase_05 AC 109 ms
72,396 KB
testcase_06 AC 2,881 ms
243,680 KB
testcase_07 AC 112 ms
72,536 KB
testcase_08 AC 2,851 ms
244,144 KB
testcase_09 AC 2,643 ms
229,392 KB
testcase_10 AC 676 ms
113,104 KB
testcase_11 AC 284 ms
87,892 KB
testcase_12 AC 112 ms
72,304 KB
testcase_13 AC 360 ms
92,184 KB
testcase_14 AC 124 ms
77,424 KB
testcase_15 AC 2,060 ms
197,332 KB
testcase_16 AC 139 ms
78,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.buffer.readline
from functools import lru_cache

def comb2(x):
    return x*(x-1)//2

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

    @lru_cache(maxsize=None)
    def solve(a,b,c,n):
        if n == 0: return 0,0,0
        if comb2(a+b+c) == 0: return 0,0,0
        aget = 0
        bget = 0
        cget = 0
        #aを1枚てにいれる確率
        pa = comb2(a)/comb2(a+b+c)
        pb = comb2(b)/comb2(a+b+c)
        pc = comb2(c)/comb2(a+b+c)
        aget = pa * (1 + solve(a-1,b,c,n-1)[0]) + pb * solve(a,b-1,c,n-1)[0] + pc * solve(a,b,c-1,n-1)[0] + (1-(pa+pb+pc)) * solve(a,b,c,n-1)[0]
        bget = pa * solve(a-1,b,c,n-1)[1] + pb * (1 + solve(a,b-1,c,n-1)[1]) + pc * solve(a,b,c-1,n-1)[1] + (1-(pa+pb+pc)) * solve(a,b,c,n-1)[1]
        cget = pa * solve(a-1,b,c,n-1)[2] + pb * solve(a,b-1,c,n-1)[2] + pc * (1 + solve(a,b,c-1,n-1)[2]) + (1-(pa+pb+pc)) * solve(a,b,c,n-1)[2]
        return aget,bget,cget
    
    ans = solve(A,B,C,N)
    print(*ans)
             

if __name__ == '__main__':
    main()
0