結果

問題 No.425 ジャンケンの必勝法
ユーザー nisizawanisizawa
提出日時 2017-12-19 19:46:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 752 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 8,772 KB
最終ジャッジ日時 2023-08-22 06:57:57
合計ジャッジ時間 2,047 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,572 KB
testcase_01 AC 20 ms
8,716 KB
testcase_02 AC 20 ms
8,572 KB
testcase_03 AC 20 ms
8,584 KB
testcase_04 AC 21 ms
8,644 KB
testcase_05 AC 20 ms
8,720 KB
testcase_06 AC 21 ms
8,680 KB
testcase_07 AC 21 ms
8,772 KB
testcase_08 AC 20 ms
8,648 KB
testcase_09 AC 20 ms
8,604 KB
testcase_10 AC 20 ms
8,720 KB
testcase_11 AC 20 ms
8,684 KB
testcase_12 AC 21 ms
8,756 KB
testcase_13 AC 21 ms
8,752 KB
testcase_14 AC 20 ms
8,756 KB
testcase_15 AC 20 ms
8,672 KB
testcase_16 AC 21 ms
8,652 KB
testcase_17 AC 21 ms
8,684 KB
testcase_18 AC 20 ms
8,604 KB
testcase_19 AC 20 ms
8,600 KB
testcase_20 AC 20 ms
8,624 KB
testcase_21 AC 20 ms
8,580 KB
testcase_22 AC 20 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache

memo_y = [p / 200 for p in range(100 + 1)]
memo_n = [(100 - p) / 300 for p in range(100 + 1)]
memo_win = [memo_y[p] + memo_n[p] for p in range(100 + 1)]

@lru_cache(maxsize=None)
def solve(p, q, depth):
    if depth > 20:
        return 0
    
    next_depth = depth + 1
    if depth == 0:
        p0 = 0
        win = memo_win[p0]
        tie_y = memo_y[p0]
        tie_n = memo_n[p0] * solve(p, q, next_depth)
    else:
        p_y = max(0, p - q)
        p_n = min(100, p + q)
        
        win = memo_win[p]
        tie_y = memo_y[p] * solve(p_y, q, next_depth)
        tie_n = memo_n[p] * solve(p_n, q, next_depth)
    
    return win + tie_y + tie_n
    
p, q = map(int, input().split())

print(solve(p, q, 0))
0