結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
82,432 KB
testcase_01 AC 59 ms
82,176 KB
testcase_02 AC 968 ms
116,608 KB
testcase_03 AC 954 ms
116,740 KB
testcase_04 AC 951 ms
116,096 KB
testcase_05 AC 953 ms
116,736 KB
testcase_06 AC 957 ms
116,608 KB
testcase_07 AC 950 ms
116,352 KB
testcase_08 AC 961 ms
116,608 KB
testcase_09 AC 950 ms
116,608 KB
testcase_10 AC 58 ms
82,048 KB
testcase_11 AC 57 ms
82,176 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

pc = [0]
for _ in range(20): pc += [c+1 for c in pc]

def prob(pa):
    pp = [[0]*n for _ in range(n)]
    dp = [0]*(1 << n)
    dp[0] = 1
    for s in range(1 << n):
        j = pc[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