結果

問題 No.173 カードゲーム(Medium)
ユーザー maspymaspy
提出日時 2020-03-17 03:46:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 720 ms / 3,000 ms
コード長 882 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 81,316 KB
最終ジャッジ日時 2023-08-19 11:44:27
合計ジャッジ時間 6,208 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
78,188 KB
testcase_01 AC 301 ms
79,840 KB
testcase_02 AC 602 ms
81,316 KB
testcase_03 AC 615 ms
80,856 KB
testcase_04 AC 601 ms
81,224 KB
testcase_05 AC 478 ms
80,808 KB
testcase_06 AC 390 ms
78,852 KB
testcase_07 AC 353 ms
78,900 KB
testcase_08 AC 334 ms
79,220 KB
testcase_09 AC 720 ms
81,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import random

# %%
N, PA, PB = readline().split()
N = int(N)
PA = float(PA)
PB = float(PB)
A = sorted(map(int, readline().split()))
B = sorted(map(int, readline().split()))


# %%
def select_card(A, P):
    if len(A) == 1:
        return 0
    p = random.random()
    if p < P:
        return 0
    n = len(A)
    return random.randint(1, n - 1)


# %%
def simulate(N, A, B):
    SA = 0
    SB = 0
    for _ in range(N):
        i = select_card(A, PA)
        j = select_card(B, PB)
        a = A.pop(i)
        b = B.pop(j)
        if a > b:
            SA += a + b
        elif a < b:
            SB += a + b
    return SA > SB


# %%
n_trial = 10 ** 5
win = sum(simulate(N, A[:], B[:]) for _ in range(n_trial))
print(win / n_trial)
0