結果

問題 No.108 トリプルカードコンプ
ユーザー Mao-betaMao-beta
提出日時 2024-03-07 20:17:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 1,383 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 85,560 KB
最終ジャッジ日時 2024-03-07 20:17:17
合計ジャッジ時間 3,065 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,624 KB
testcase_01 AC 39 ms
55,624 KB
testcase_02 AC 49 ms
57,700 KB
testcase_03 AC 44 ms
55,616 KB
testcase_04 AC 39 ms
55,624 KB
testcase_05 AC 40 ms
55,624 KB
testcase_06 AC 37 ms
55,624 KB
testcase_07 AC 94 ms
85,560 KB
testcase_08 AC 87 ms
85,560 KB
testcase_09 AC 88 ms
85,560 KB
testcase_10 AC 83 ms
85,560 KB
testcase_11 AC 84 ms
85,560 KB
testcase_12 AC 38 ms
57,700 KB
testcase_13 AC 54 ms
70,832 KB
testcase_14 AC 54 ms
70,840 KB
testcase_15 AC 56 ms
70,840 KB
testcase_16 AC 67 ms
70,832 KB
testcase_17 AC 54 ms
70,852 KB
testcase_18 AC 81 ms
84,664 KB
testcase_19 AC 79 ms
84,284 KB
testcase_20 AC 100 ms
85,432 KB
testcase_21 AC 88 ms
85,432 KB
testcase_22 AC 86 ms
84,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N = NI()
    A = NLI()
    INF = 10**20
    E = [[[INF]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    C = [0] * 3
    for a in A:
        if a >= 3:
            continue
        C[a] += 1
    E[0][0][0] = 0
    for n0 in range(N+1):
        for n1 in range(N+1-n0):
            for n2 in range(N+1-n0-n1):
                if n0 == n1 == n2 == 0:
                    continue
                e = 1
                if n0 > 0:
                    e += E[n0-1][n1+1][n2] * n0 / N
                if n1 > 0:
                    e += E[n0][n1-1][n2+1] * n1 / N
                if n2 > 0:
                    e += E[n0][n1][n2-1] * n2 / N
                a = (N-n0-n1-n2) / N
                E[n0][n1][n2] = e / (1-a)
                
    print(E[C[0]][C[1]][C[2]])


if __name__ == "__main__":
    main()
0