結果
問題 | No.1688 Veterinarian |
ユーザー | asumo0729 |
提出日時 | 2021-09-24 22:10:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 355 ms / 3,000 ms |
コード長 | 2,401 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 150,784 KB |
最終ジャッジ日時 | 2024-07-05 10:40:39 |
合計ジャッジ時間 | 2,699 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
54,400 KB |
testcase_01 | AC | 47 ms
55,296 KB |
testcase_02 | AC | 47 ms
55,552 KB |
testcase_03 | AC | 45 ms
54,784 KB |
testcase_04 | AC | 46 ms
54,400 KB |
testcase_05 | AC | 50 ms
55,296 KB |
testcase_06 | AC | 66 ms
70,016 KB |
testcase_07 | AC | 78 ms
74,624 KB |
testcase_08 | AC | 355 ms
150,784 KB |
testcase_09 | AC | 341 ms
146,560 KB |
testcase_10 | AC | 146 ms
84,224 KB |
testcase_11 | AC | 127 ms
84,608 KB |
testcase_12 | AC | 68 ms
68,992 KB |
testcase_13 | AC | 95 ms
77,184 KB |
testcase_14 | AC | 92 ms
78,080 KB |
testcase_15 | AC | 135 ms
82,688 KB |
testcase_16 | AC | 66 ms
67,328 KB |
ソースコード
import sys from operator import itemgetter from collections import defaultdict, deque import heapq import bisect stdin=sys.stdin sys.setrecursionlimit(10 ** 8) ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() Yp=lambda:print('Yes') Np=lambda:print('No') inf = 1 << 60 eps = 1e-9 sortkey = itemgetter(0) class Comb(): def __init__(self, N, mod): self.N = N self.mod = mod self.fa = self.fa_fainv()[0] self.fainv = self.fa_fainv()[1] def fa_fainv(self): fa = [1] for i in range(1, self.N + 1): fa.append(fa[-1] * i % self.mod) fainv = [pow(fa[-1],self.mod - 2,self.mod)] for i in range(1, self.N + 1)[::-1]: fainv.append(fainv[-1] * i % self.mod) fainv = fainv[::-1] return fa, fainv def calcu_comb(self, a, b): if b == 0: return 1 return self.fa[a] * self.fainv[a - b] * self.fainv[b] % self.mod ############################################################### A, B, C, N = lp() dp = [[[[0 for _ in range(C + 1)] for _ in range(B + 1)] for _ in range(A + 1)] for _ in range(N + 1)] dp[0][A][B][C] = 1 for i in range(N): for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if dp[i][a][b][c] == 0: continue all_pos = 1 if a > 1: pos = (a * (a - 1) / 2) / ((a + b + c) * (a + b + c - 1) / 2) all_pos -= pos dp[i + 1][a - 1][b][c] += dp[i][a][b][c] * pos if b > 1: pos = (b * (b - 1) / 2) / ((a + b + c) * (a + b + c - 1) / 2) all_pos -= pos dp[i + 1][a][b - 1][c] += dp[i][a][b][c] * pos if c > 1: pos = (c * (c - 1) / 2) / ((a + b + c) * (a + b + c - 1) / 2) all_pos -= pos dp[i + 1][a][b][c - 1] += dp[i][a][b][c] * pos dp[i + 1][a][b][c] += dp[i][a][b][c] * all_pos x = 0 y = 0 z = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): x += dp[-1][a][b][c] * (A - a) y += dp[-1][a][b][c] * (B - b) z += dp[-1][a][b][c] * (C - c) print(x, y, z)