結果
問題 | No.1151 チャレンジゲーム |
ユーザー |
![]() |
提出日時 | 2021-06-10 00:50:04 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,981 ms / 2,000 ms |
コード長 | 1,761 bytes |
コンパイル時間 | 241 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-11-29 02:52:10 |
合計ジャッジ時間 | 59,129 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 # md = 10**9+7 from functools import lru_cache # nullさんの取ったカードがs、kiriさんの取ったカードがtのときに、nullさんの勝つ確率 @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 s1 = s | 1 << i p1 = 1 if popcnt(used) == n-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(s1, t | 1 << j)/aj+p(s1, t)*(aj-1)/aj) cur = 1 for j, aj in enumerate(aa): if used >> j & 1: continue p2 = p(s, t | 1 << j) cur = min(cur, (aj*p1-p2+ai*p2)/(ai+aj-1)) res = max(res, cur) return res popcnt = lambda x: bin(x).count("1") n = II() aa = LI() tot = sum(aa) print(p(0, 0))