結果
問題 |
No.1151 チャレンジゲーム
|
ユーザー |
![]() |
提出日時 | 2021-06-11 01:24:42 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,767 ms / 2,000 ms |
コード長 | 1,305 bytes |
コンパイル時間 | 500 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 19,600 KB |
最終ジャッジ日時 | 2024-11-30 13:45:15 |
合計ジャッジ時間 | 53,259 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
import sys sys.setrecursionlimit(200005) def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) from functools import lru_cache # 先手の取ったカードがs、後手の取ったカードがtのときに、先手の勝つ確率 @lru_cache(None) def p(s, t): used = s | t # 全部取り終わった場合 if used == (1 << n)-1: x = sum(a for i, a in enumerate(aa) if s >> i & 1) y = tot-x return x > y res = 0 for i, ai in enumerate(aa): if used >> i & 1: continue si = s | 1 << i # p1を求める p1 = 1 if popcnt(used) == n-1: # 先手が最後の1枚を取った場合 p1 = p(s | 1 << i, t) else: for j, aj in enumerate(aa): if j == i: continue if used >> j & 1: continue p1 = min(p1, p(si, t | 1 << j)/aj+p(si, t)*(aj-1)/aj) # kを全探索する mn = 1 for k, ak in enumerate(aa): if used >> k & 1: continue tk = t | 1 << k mn = min(mn, (ak*p1+(ai-1)*p(s, tk))/(ai+ak-1)) res = max(res, mn) return res popcnt = lambda x: bin(x).count("1") n = II() aa = LI() tot = sum(aa) print(p(0, 0))