結果

問題 No.108 トリプルカードコンプ
コンテスト
ユーザー Navier_Boltzmann
提出日時 2023-06-16 09:06:55
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 677 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 155 ms
コンパイル使用メモリ 85,768 KB
実行使用メモリ 143,184 KB
最終ジャッジ日時 2026-03-10 01:52:51
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline


N = int(input())
A = list(map(int,input().split()))
X = [0]*4
for a in A:
    m = min(a,3)
    X[m] += 1
    
mem = defaultdict(lambda:-1)
mem[(0,0,0,N)]=0
def f(X):
    if mem[X]!=-1:
        return mem[X]
    Z = list(X)
    
    tmp = 0
    for i in range(3):
        
        if Z[i]==0:
            continue
        
        Z[i+1] += 1
        Z[i] -= 1
        tmp += (Z[i]+1)*(1 + f(tuple(Z)))
        Z[i+1] -= 1
        Z[i] += 1
    tmp += Z[3]
    tmp /= (N-Z[3])
    mem[tuple(X)] = tmp
    return tmp
    
print(f(tuple(X)))
0