結果

問題 No.1688 Veterinarian
ユーザー titiatitia
提出日時 2021-09-24 23:09:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,941 ms / 3,000 ms
コード長 804 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 11,036 KB
実行使用メモリ 101,564 KB
最終ジャッジ日時 2023-09-18 22:15:36
合計ジャッジ時間 12,720 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,720 KB
testcase_01 AC 22 ms
8,836 KB
testcase_02 AC 29 ms
9,092 KB
testcase_03 AC 20 ms
8,800 KB
testcase_04 AC 20 ms
8,780 KB
testcase_05 AC 20 ms
8,840 KB
testcase_06 AC 2,930 ms
101,564 KB
testcase_07 AC 20 ms
8,792 KB
testcase_08 AC 2,941 ms
100,992 KB
testcase_09 AC 2,628 ms
94,892 KB
testcase_10 AC 546 ms
28,108 KB
testcase_11 AC 149 ms
13,820 KB
testcase_12 AC 20 ms
8,660 KB
testcase_13 AC 226 ms
17,040 KB
testcase_14 AC 22 ms
8,800 KB
testcase_15 AC 2,021 ms
78,556 KB
testcase_16 AC 23 ms
8,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

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

def plus(A,B):
    ANS=[0,0,0]
    for i in range(3):
        ANS[i]=A[i]+B[i]

    return ANS

def mul(k,A):
    ANS=[0,0,0]
    for i in range(3):
        ANS[i]=k*A[i]
    return ANS
        
from functools import lru_cache
@lru_cache(maxsize=None)
def calc(A,B,C,N):
    if N==0:
        return [0,0,0]
    ALL=c2(A+B+C)

    if ALL==0:
        return [0,0,0]

    ANS=[0,0,0]

    ANS=plus(ANS,mul(c2(A)/ALL,plus([1,0,0],calc(A-1,B,C,N-1))))
    ANS=plus(ANS,mul(c2(B)/ALL,plus([0,1,0],calc(A,B-1,C,N-1))))
    ANS=plus(ANS,mul(c2(C)/ALL,plus([0,0,1],calc(A,B,C-1,N-1))))
    ANS=plus(ANS,mul((ALL-c2(A)-c2(B)-c2(C))/ALL,calc(A,B,C,N-1)))

    return ANS
    
print(*calc(A,B,C,N))
    
    
0