結果

問題 No.108 トリプルカードコンプ
ユーザー nephrologistnephrologist
提出日時 2021-01-28 00:46:04
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 464 ms / 5,000 ms
コード長 616 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 86,772 KB
実行使用メモリ 146,332 KB
最終ジャッジ日時 2023-09-07 07:28:08
合計ジャッジ時間 5,642 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
72,084 KB
testcase_01 AC 109 ms
72,344 KB
testcase_02 AC 112 ms
72,212 KB
testcase_03 AC 109 ms
72,444 KB
testcase_04 AC 111 ms
72,284 KB
testcase_05 AC 107 ms
72,196 KB
testcase_06 AC 106 ms
72,440 KB
testcase_07 AC 464 ms
146,332 KB
testcase_08 AC 134 ms
79,404 KB
testcase_09 AC 111 ms
72,488 KB
testcase_10 AC 108 ms
72,300 KB
testcase_11 AC 110 ms
72,228 KB
testcase_12 AC 107 ms
72,084 KB
testcase_13 AC 175 ms
84,132 KB
testcase_14 AC 144 ms
78,764 KB
testcase_15 AC 139 ms
78,876 KB
testcase_16 AC 159 ms
80,052 KB
testcase_17 AC 117 ms
77,416 KB
testcase_18 AC 363 ms
122,788 KB
testcase_19 AC 219 ms
95,436 KB
testcase_20 AC 172 ms
83,928 KB
testcase_21 AC 290 ms
107,744 KB
testcase_22 AC 140 ms
79,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys

sys.setrecursionlimit(4100000)
n = int(input())
A = list(map(int, input().split()))

n1, n2, n3 = 0, 0, 0
for a in A:
    a = min(a, 3)
    if a == 0:
        n3 += 1
    if a == 1:
        n2 += 1
    if a == 2:
        n1 += 1


@lru_cache(None)
def calc(a, b, c):
    if a == 0 and b == 0 and c == 0:
        return 0

    res = n
    goukei = a + b + c
    if c:
        res += (calc(a, b + 1, c - 1)) * c
    if b:
        res += (calc(a + 1, b - 1, c)) * b
    if a:
        res += (calc(a - 1, b, c)) * a
    res /= goukei
    return res


print(calc(n1, n2, n3))

0