結果

問題 No.174 カードゲーム(Hard)
ユーザー vwxyzvwxyz
提出日時 2021-08-07 04:41:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,966 ms / 2,000 ms
コード長 2,204 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 81,596 KB
実行使用メモリ 115,548 KB
最終ジャッジ日時 2023-10-17 10:12:53
合計ジャッジ時間 17,793 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
88,548 KB
testcase_01 AC 145 ms
88,556 KB
testcase_02 AC 1,955 ms
115,520 KB
testcase_03 AC 1,949 ms
115,544 KB
testcase_04 AC 1,966 ms
115,548 KB
testcase_05 AC 1,964 ms
115,548 KB
testcase_06 AC 1,953 ms
115,548 KB
testcase_07 AC 1,948 ms
115,548 KB
testcase_08 AC 1,950 ms
115,548 KB
testcase_09 AC 1,962 ms
115,548 KB
testcase_10 AC 148 ms
88,592 KB
testcase_11 AC 149 ms
88,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines

N,PA,PB=readline().split()
N=int(N)
PA=float(PA)
PB=float(PB)
A=list(map(int,readline().split()))
B=list(map(int,readline().split()))
A.sort()
B.sort()
dpA=[0]*(1<<N)
dpA[(1<<N)-1]=1
cardA=[[0]*N for i in range(N+1)]
for bit in range((1<<N)-1,-1,-1):
    cnt=sum(bit>>i&1 for i in range(N))
    for i in range(N):
        if bit>>i&1:
            break
    for j in range(N):
        if not bit>>j&1:
            continue
        if i==j:
            if cnt==1:
                dpA[bit^1<<j]+=dpA[bit]
                cardA[cnt][j]+=dpA[bit]
            else:
                dpA[bit^1<<j]+=dpA[bit]*PA
                cardA[cnt][j]+=dpA[bit]*PA
        else:
            dpA[bit^1<<j]+=dpA[bit]*(1-PA)/(cnt-1)
            cardA[cnt][j]+=dpA[bit]*(1-PA)/(cnt-1)
dpB=[0]*(1<<N)
dpB[(1<<N)-1]=1
cardB=[[0]*N for i in range(N+1)]
for bit in range((1<<N)-1,-1,-1):
    cnt=sum(bit>>i&1 for i in range(N))
    for i in range(N):
        if bit>>i&1:
            break
    for j in range(N):
        if not bit>>j&1:
            continue
        if i==j:
            if cnt==1:
                dpB[bit^1<<j]+=dpB[bit]
                cardB[cnt][j]+=dpB[bit]
            else:
                dpB[bit^1<<j]+=dpB[bit]*PB
                cardB[cnt][j]+=dpB[bit]*PB
        else:
            dpB[bit^1<<j]+=dpB[bit]*(1-PB)/(cnt-1)
            cardB[cnt][j]+=dpB[bit]*(1-PB)/(cnt-1)
ans=0
for cnt in range(1+N):
    for i in range(N):
        for j in range(N):
            if A[i]>B[j]:
                ans+=cardA[cnt][i]*cardB[cnt][j]*(A[i]+B[j])
print(ans)
0