結果

問題 No.306 さいたま2008
ユーザー kichirb3kichirb3
提出日時 2018-03-24 22:24:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 9,020 KB
最終ジャッジ日時 2023-09-07 08:58:31
合計ジャッジ時間 1,728 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
8,904 KB
testcase_01 AC 26 ms
8,892 KB
testcase_02 AC 21 ms
8,952 KB
testcase_03 AC 23 ms
8,936 KB
testcase_04 AC 23 ms
8,920 KB
testcase_05 AC 22 ms
8,932 KB
testcase_06 AC 23 ms
8,876 KB
testcase_07 AC 23 ms
8,888 KB
testcase_08 AC 23 ms
9,020 KB
testcase_09 AC 23 ms
8,860 KB
testcase_10 AC 23 ms
8,996 KB
testcase_11 AC 23 ms
8,872 KB
testcase_12 AC 23 ms
8,784 KB
testcase_13 AC 21 ms
8,816 KB
testcase_14 AC 21 ms
8,796 KB
testcase_15 AC 23 ms
8,844 KB
testcase_16 AC 22 ms
8,992 KB
testcase_17 AC 22 ms
8,856 KB
testcase_18 AC 21 ms
8,864 KB
testcase_19 AC 23 ms
8,820 KB
testcase_20 AC 22 ms
8,844 KB
testcase_21 AC 22 ms
8,856 KB
testcase_22 AC 23 ms
8,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.306 さいたま2008
https://yukicoder.me/problems/no/306

"""
import sys
from sys import stdin
from decimal import *
input = stdin.readline


def calc_dist(ax, ay, bx, by, py):
    ap = (ax*ax + (ay-py)*(ay-py))
    bp = (bx*bx + (by-py)*(by-py))
    return ap.sqrt() + bp.sqrt()


def solve(ax, ay, bx, by):
    uy = Decimal(max(ay, by))
    ly = Decimal(min(ay, by))
    if uy == ly:
        return ly

    dax = Decimal(ax)
    day = Decimal(ay)
    dbx = Decimal(bx)
    dby = Decimal(by)
    getcontext().prec = 28

    for _ in range(100):
        py1 = Decimal((ly*2 + uy) / 3)
        mid1_score = calc_dist(dax, day, dbx, dby, py1)
        py2 = Decimal((ly + uy*2) / 3)
        mid2_score = calc_dist(dax, day, dbx, dby, py2)
        if mid2_score > mid1_score:
            uy = py2
        else:
            ly = py1
    return (uy + ly) / 2


def main(args):
    ax, ay = map(float, input().split())
    bx, by = map(float, input().split())
    ans = solve(ax, ay, bx, by)
    print('{:f}'.format(ans))


if __name__ == '__main__':
    main(sys.argv[1:])
0