結果

問題 No.173 カードゲーム(Medium)
ユーザー maspymaspy
提出日時 2020-03-17 03:46:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,968 ms / 3,000 ms
コード長 882 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 8,968 KB
最終ジャッジ日時 2023-08-19 11:32:39
合計ジャッジ時間 12,440 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
8,844 KB
testcase_01 AC 260 ms
8,872 KB
testcase_02 AC 1,559 ms
8,916 KB
testcase_03 AC 1,571 ms
8,848 KB
testcase_04 AC 1,536 ms
8,916 KB
testcase_05 AC 1,291 ms
8,768 KB
testcase_06 AC 1,104 ms
8,856 KB
testcase_07 AC 1,009 ms
8,964 KB
testcase_08 AC 994 ms
8,968 KB
testcase_09 AC 1,968 ms
8,856 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