結果
問題 |
No.108 トリプルカードコンプ
|
ユーザー |
![]() |
提出日時 | 2022-11-22 22:24:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 376 ms / 5,000 ms |
コード長 | 831 bytes |
コンパイル時間 | 639 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 135,036 KB |
最終ジャッジ日時 | 2024-09-23 06:01:55 |
合計ジャッジ時間 | 3,781 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
from typing import List, Tuple, Callable, TypeVar import sys import itertools import heapq import bisect import math from collections import deque, defaultdict, Counter from functools import lru_cache, cmp_to_key input = sys.stdin.readline if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] N = int(input()) A = readlist() cnt = defaultdict(int) for a in A: cnt[a] += 1 @lru_cache(None) def solve(a, b, c): if a + b + c == 0: return 0 acc = 0 if a: acc += a * solve(a - 1, b + 1, c) if b: acc += b * solve(a, b - 1, c + 1) if c: acc += c * solve(a, b, c - 1) return (acc + N) / (a + b + c) print(solve(cnt[0], cnt[1], cnt[2]))