結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
vwxyz
|
| 提出日時 | 2021-08-07 04:41:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,983 ms / 2,000 ms |
| コード長 | 2,204 bytes |
| コンパイル時間 | 849 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 117,020 KB |
| 最終ジャッジ日時 | 2024-09-17 08:38:53 |
| 合計ジャッジ時間 | 17,710 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
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)
vwxyz