結果

問題 No.425 ジャンケンの必勝法
ユーザー H3PO4H3PO4
提出日時 2022-04-24 08:37:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 377 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 10,744 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-09-08 01:44:49
合計ジャッジ時間 2,119 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,572 KB
testcase_01 AC 20 ms
8,572 KB
testcase_02 AC 20 ms
8,676 KB
testcase_03 AC 19 ms
8,584 KB
testcase_04 AC 21 ms
8,620 KB
testcase_05 AC 20 ms
8,612 KB
testcase_06 AC 20 ms
8,624 KB
testcase_07 AC 20 ms
8,696 KB
testcase_08 AC 19 ms
8,608 KB
testcase_09 AC 20 ms
8,560 KB
testcase_10 AC 20 ms
8,632 KB
testcase_11 AC 20 ms
8,740 KB
testcase_12 AC 19 ms
8,564 KB
testcase_13 AC 20 ms
8,664 KB
testcase_14 AC 20 ms
8,520 KB
testcase_15 AC 20 ms
8,564 KB
testcase_16 AC 19 ms
8,580 KB
testcase_17 AC 20 ms
8,592 KB
testcase_18 AC 20 ms
8,496 KB
testcase_19 AC 20 ms
8,684 KB
testcase_20 AC 20 ms
8,632 KB
testcase_21 AC 20 ms
8,628 KB
testcase_22 AC 20 ms
8,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

P, Q = map(int, input().split())


@lru_cache
def rec(p: int, n: int) -> float:
    if n > 20:
        return 0
    pf = p / 100

    res = 0
    res += pf / 2
    res += pf / 2 * rec(max(p - Q, 0), n + 1)
    res += (1 - pf) / 3
    res += (1 - pf) / 3 * rec(min(p + Q, 100), n + 1)
    return res


ans = 1 / 3 * rec(P, 1) + 1 / 3
print(ans)
0