結果

問題 No.173 カードゲーム(Medium)
ユーザー norioc
提出日時 2025-02-06 04:05:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,930 ms / 3,000 ms
コード長 918 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 78,872 KB
最終ジャッジ日時 2025-02-06 04:05:33
合計ジャッジ時間 20,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import random

a = input().split()
N = int(a[0])
PA = float(a[1])
PB = float(a[2])

A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.sort()
B.sort()


def select(cards: list[int], prob: float) -> list[int]:
    cands = cards.copy()
    res = []
    for i in range(len(cards)):
        p = random.random()
        if p <= prob or len(cands) == 1:
            res.append(cands[0])
            del cands[0]
        else:
            k = random.randint(1, len(cands)-1)
            res.append(cands[k])
            del cands[k]

    return res


def judge(xs, ys) -> bool:
    fst = 0
    snd = 0
    for x, y in zip(xs, ys):
        if x > y:
            fst += x + y
        else:
            snd += x + y

    return fst > snd


trials = 500_000
win = 0
for _ in range(trials):
    xs = select(A, PA)
    ys = select(B, PB)
    if judge(xs, ys):
        win += 1

ans = win / trials
print(ans)
0