結果
| 問題 |
No.108 トリプルカードコンプ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-02 17:01:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 140 ms / 5,000 ms |
| コード長 | 761 bytes |
| コンパイル時間 | 371 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 81,280 KB |
| 最終ジャッジ日時 | 2024-06-11 09:29:20 |
| 合計ジャッジ時間 | 2,538 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
N = int(input())
*A, = map(int, input().split())
c0, c1, c2 = A.count(0), A.count(1), A.count(2)
DP = [[[None]*(c0+c1+c2-(i+j)+1) for j in range(c1+c0-i+1)]
for i in range(c0+1)]
def solve(a, b, c):
if a == b == c == 0:
return 0
if DP[a][b][c] is not None:
return DP[a][b][c]
ans = 0
if a > 0:
ans += a * solve(a-1, b+1, c)
if b > 0:
ans += b * solve(a, b-1, c+1)
if c > 0:
ans += c * solve(a, b, c-1)
DP[a][b][c] = (ans + N) / (a+b+c)
return DP[a][b][c]
print(solve(c0, c1, c2))
if __name__ == '__main__':
main()