結果

問題 No.174 カードゲーム(Hard)
ユーザー mkawa2mkawa2
提出日時 2023-04-11 22:18:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,875 ms / 2,000 ms
コード長 1,584 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 101,584 KB
最終ジャッジ日時 2024-04-16 18:06:10
合計ジャッジ時間 16,041 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 40 ms
52,864 KB
testcase_02 AC 1,864 ms
101,360 KB
testcase_03 AC 1,875 ms
101,432 KB
testcase_04 AC 1,870 ms
100,964 KB
testcase_05 AC 1,871 ms
101,228 KB
testcase_06 AC 1,868 ms
101,316 KB
testcase_07 AC 1,850 ms
100,976 KB
testcase_08 AC 1,874 ms
101,288 KB
testcase_09 AC 1,853 ms
101,584 KB
testcase_10 AC 38 ms
52,352 KB
testcase_11 AC 39 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

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 = (1 << 63)-1
# md = 10**9+7
md = 998244353

def popcnt(a): return bin(a).count("1")

def prob(pa):
    pp = [[0]*n for _ in range(n)]
    dp = [0]*(1 << n)
    dp[0] = 1
    for s in range(1 << n):
        j = popcnt(s)
        p = -1
        for i in range(n):
            if s >> i & 1: continue
            if j == n-1:
                pp[i][j] += dp[s]
            elif p == -1:
                dp[s | 1 << i] += dp[s]*pa
                pp[i][j] += dp[s]*pa
                p = (1-pa)/(n-j-1)
            else:
                dp[s | 1 << i] += dp[s]*p
                pp[i][j] += dp[s]*p
    return pp

n, pa, pb = SI().split()
n = int(n)
pa = float(pa)
pb = float(pb)
aa = sorted(LI())
bb = sorted(LI())

pp = prob(pa)
qq = prob(pb)

ans = 0
for ai, a in enumerate(aa):
    for bi, b in enumerate(bb):
        if a < b: break
        for p, q in zip(pp[ai], qq[bi]):
            ans += p*q*(a+b)

print(f"{ans:.10f}")
0