結果

問題 No.419 直角三角形
ユーザー lam6er
提出日時 2025-03-20 20:18:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 1,000 ms
コード長 625 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 83,036 KB
実行使用メモリ 80,828 KB
最終ジャッジ日時 2025-03-20 20:19:41
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from decimal import Decimal, getcontext, ROUND_HALF_UP

# Set precision and rounding mode to handle accurate decimal operations
getcontext().prec = 20
getcontext().rounding = ROUND_HALF_UP

a, b = map(int, input().split())

if a != b:
    c = max(a, b)
    d = min(a, b)
    # Calculate c² - d² using Decimal for high precision
    cs = Decimal(c)
    ds = Decimal(d)
    res = (cs**2 - ds**2).sqrt()
else:
    # Calculate hypotenuse when both sides are equal
    res = (Decimal(a)**2 * 2).sqrt()

# Format the result to 10 decimal places
formatted_res = res.quantize(Decimal('1.0000000000'))
print(f"{formatted_res:.10f}")
0