結果
| 問題 |
No.1688 Veterinarian
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-09-24 23:08:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,740 ms / 3,000 ms |
| コード長 | 804 bytes |
| コンパイル時間 | 211 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 236,276 KB |
| 最終ジャッジ日時 | 2024-07-05 11:25:52 |
| 合計ジャッジ時間 | 9,135 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
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))
titia