結果

問題 No.787 Mice and Traitors(ネズミ達と裏切り者)
ユーザー lam6er
提出日時 2025-03-20 20:20:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,508 KB
実行使用メモリ 80,624 KB
最終ジャッジ日時 2025-03-20 20:21:01
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import Decimal, getcontext

getcontext().prec = 50  # Set high precision for accurate calculations

# Read input values as strings to handle decimal points accurately
p_str, q_str = input().split()

p = Decimal(p_str)
q = Decimal(q_str)

# Calculate the numerator and denominator components
numerator = p * q
term2 = (Decimal(100) - p) * (Decimal(100) - q)
denominator = numerator + term2

# Compute the result using high precision division
result = (numerator / denominator) * Decimal(100)

# Format the result to ensure sufficient decimal places without unnecessary trailing zeros
formatted_result = format(result, 'f')  # Convert to string in fixed-point notation

# Remove trailing zeros and unnecessary decimal points if any
if '.' in formatted_result:
    formatted_result = formatted_result.rstrip('0').rstrip('.')
else:
    formatted_result += '.'

# Ensure at least one decimal place for consistency with sample outputs
if '.' not in formatted_result:
    formatted_result += '.0'

print(formatted_result)
0