結果

問題 No.173 カードゲーム(Medium)
ユーザー rpy3cpprpy3cpp
提出日時 2015-03-27 00:53:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 611 ms / 3,000 ms
コード長 1,230 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 80,592 KB
最終ジャッジ日時 2023-09-11 10:39:26
合計ジャッジ時間 5,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
77,396 KB
testcase_01 AC 285 ms
80,208 KB
testcase_02 AC 540 ms
80,152 KB
testcase_03 AC 547 ms
80,316 KB
testcase_04 AC 539 ms
80,500 KB
testcase_05 AC 403 ms
79,620 KB
testcase_06 AC 335 ms
78,620 KB
testcase_07 AC 309 ms
78,784 KB
testcase_08 AC 293 ms
78,956 KB
testcase_09 AC 611 ms
80,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, Pa, Pb = input().split()
    N = int(N)
    Pa = float(Pa)
    Pb = float(Pb)
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    A.sort(reverse=True)
    B.sort(reverse=True)
    return N, Pa, Pb, A, B

def solve(N, Pa, Pb, A, B):
    Nsim = 10**5
    Awin = 0
    for i in range(Nsim):
        if simulate(N, Pa, Pb, A[:], B[:]):
            Awin += 1
    return Awin / Nsim

import random
def simulate(N, Pa, Pb, A, B):
    scoreA = 0
    scoreB = 0
    for i in range(N-1, 0, -1):
        ra = random.random()
        rb = random.random()
        if ra < Pa:
            pa = A[-1]
            del A[-1]
        else:
            ia = random.randrange(0, i)
            pa = A[ia]
            del A[ia]
        if rb < Pb:
            pb = B[-1]
            del B[-1]
        else:
            ib = random.randrange(0, i)
            pb = B[ib]
            del B[ib]
        if pa > pb:
            scoreA += pa + pb
        elif pa < pb:
            scoreB += pa + pb
    pa = A[0]
    pb = B[0]
    if pa > pb:
        scoreA += pa + pb
    elif pa < pb:
        scoreB += pa + pb
    return scoreA > scoreB

N, Pa, Pb, A, B = read_data()
print(solve(N, Pa, Pb, A, B))
0