結果

問題 No.1151 チャレンジゲーム
ユーザー takakin
提出日時 2020-08-10 22:50:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 842 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2024-10-08 18:51:25
合計ジャッジ時間 61,302 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38 TLE * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
import itertools
n=int(input())
A=[int(i) for i in input().split()]
tot=sum(A)
P=[[0]*(3**n) for _ in range(2)]
for p in itertools.product(range(3),repeat=n):
	index,sen=0,0
	Mitei=[]
	for i in range(n):
		index+=p[i]*3**i
		if p[i]==0:
			sen+=A[i]
		if p[i]==2:
			Mitei.append(i)
	if not Mitei:
		if sen*2>tot:
			for j in range(2):
				P[j][index]=1
		else:
			for j in range(2):
				P[j][index]=0
	else:
		pa0,pa1=0,0
		for m1 in Mitei:
			p0,p1=0,1
			for m2 in Mitei:
				a1,a2=A[m1],A[m2]
				pp0=(P[1][index-2*3**m1]/a1 + P[0][index-3**m2]*(a1-1)/(a1*a2))*a1*a2/(a1+a2-1)
				pp1=(P[0][index-3**m2]/a2 + P[1][index-2*3**m1]*(a2-1)/(a1*a2))*a1*a2/(a1+a2-1)
				if pp1<=p1:
					p0,p1=pp0,pp1
			if p0>=pa0:
				pa0,pa1=p0,p1
		P[0][index]=pa0
		P[1][index]=pa1

print(P[0][-1])

0