結果

問題 No.174 カードゲーム(Hard)
ユーザー nohtaraynohtaray
提出日時 2019-06-14 23:59:46
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 2,077 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 9,912 KB
最終ジャッジ日時 2023-08-09 19:44:51
合計ジャッジ時間 1,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")



N, PA, PB = sys.stdin.readline().rstrip().split()
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
N = int(N)
PA = float(PA)
PB = float(PB)
A.sort()
B.sort()


def probabilities(cards, first_p):
    """
    :param list of int cards:
    :param float first_p: 最初のカードを選ぶ確率
    :return:
    """
    cards.sort()
    # ret[i][j]: i 試合目で cards[j] を出す確率
    ret = np.zeros((N, N))
    # dp[bit]: 持ってるカードが bit になる確率
    # 左から i 番目のビットが立ってたら cards[i] が手持ちにある
    # dp する過程で ret を計算する
    dp = np.zeros(1 << N)
    # 初期
    dp[(1 << N) - 1] = 1
    states = {(1 << N) - 1}
    for step in range(N):
        nexts = set()
        for st in states:
            first = step < N - 1
            for b in range(N):
                mask = 1 << b
                next_st = st ^ mask
                if next_st > st:
                    continue
                nexts.add(next_st)
                if first:
                    p = dp[st] * first_p
                    first = False
                elif step == N - 1:
                    p = dp[st]
                else:
                    p = dp[st] * (1 - first_p) / (N - step - 1)
                dp[next_st] += p
                ret[step][b] += p
        states = nexts
    return ret


np.set_printoptions(suppress=True)

AP = probabilities(cards=A, first_p=PA)
BP = probabilities(cards=B, first_p=PB)

ans = 0
for step in range(N):
    for a in range(N):
        for b in range(N):
            if A[a] > B[b]:
                ans += (A[a] + B[b]) * AP[step][a] * BP[step][b]
print(ans)
0