結果

問題 No.425 ジャンケンの必勝法
ユーザー gew1fw
提出日時 2025-06-12 20:26:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,539 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,896 KB
実行使用メモリ 62,484 KB
最終ジャッジ日時 2025-06-12 20:27:04
合計ジャッジ時間 2,022 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 2
other AC * 5 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    p0, q = map(int, sys.stdin.readline().split())
    p0_percent = p0 / 100.0
    q_percent = q / 100.0

    # Convert q to percentage change
    q_change = q  # since p is in [0, 100], q is in [0, 100]

    # Initialize F[p] for all p in 0-100
    F = [0.5] * 101
    max_iterations = 100000
    threshold = 1e-9

    for _ in range(max_iterations):
        new_F = F.copy()
        max_diff = 0.0
        for p in range(101):
            current_p = p / 100.0
            # Compute probabilities
            P_N = current_p * 0.5 + (1 - current_p) * (1/3)
            P_C = (1 - current_p) * (1/3)
            P_Tie = current_p * 0.5 + (1 - current_p) * (1/3)

            # Compute next p values
            next_p_minus = max(p - q_change, 0)
            next_p_plus = min(p + q_change, 100)

            # Calculate E
            prob_strategy = current_p
            prob_no_strategy = 1 - current_p
            E = prob_strategy * F[next_p_minus] + prob_no_strategy * F[next_p_plus]

            # Update new_F[p]
            new_F_val = P_N * 1 + P_Tie * E
            new_F[p] = new_F_val

            # Update max_diff
            diff = abs(new_F[p] - F[p])
            if diff > max_diff:
                max_diff = diff

        # Check for convergence
        if max_diff < threshold:
            break
        F = new_F

    # After convergence, compute the initial probability P
    initial_P = (1/3) + (1/3) * F[p0]
    print("{0:.10f}".format(initial_P))

if __name__ == '__main__':
    main()
0