結果

問題 No.168 ものさし
ユーザー しらっ亭しらっ亭
提出日時 2015-06-19 01:02:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,128 KB
実行使用メモリ 42,088 KB
最終ジャッジ日時 2023-08-25 20:57:30
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
16,336 KB
testcase_01 AC 17 ms
8,216 KB
testcase_02 AC 17 ms
8,116 KB
testcase_03 AC 16 ms
8,052 KB
testcase_04 AC 16 ms
8,228 KB
testcase_05 AC 16 ms
8,204 KB
testcase_06 AC 17 ms
8,164 KB
testcase_07 AC 17 ms
8,220 KB
testcase_08 AC 17 ms
8,212 KB
testcase_09 AC 20 ms
8,120 KB
testcase_10 AC 26 ms
9,364 KB
testcase_11 AC 97 ms
15,264 KB
testcase_12 AC 294 ms
30,504 KB
testcase_13 AC 397 ms
39,296 KB
testcase_14 AC 257 ms
38,076 KB
testcase_15 AC 17 ms
8,160 KB
testcase_16 AC 19 ms
8,116 KB
testcase_17 AC 22 ms
8,576 KB
testcase_18 AC 35 ms
9,984 KB
testcase_19 AC 399 ms
41,208 KB
testcase_20 AC 318 ms
42,088 KB
testcase_21 AC 408 ms
41,768 KB
testcase_22 AC 321 ms
42,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import math


def d2(p1, p2):
    return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2


def dij(n, ps):
    start = 0
    goal = n - 1

    d2mat = [[0] * n for i in range(n)]

    pset = set(range(n))

    for i in range(n):
        for j in range(i + 1, n):
            d2mat[i][j] = d2mat[j][i] = d2(ps[i], ps[j])

    d = [d2mat[start][i] for i in range(n)]

    hq = []
    for i in range(n):
        heappush(hq, (d[i], i))

    while hq:
        m, i = heappop(hq)

        if d[i] < m:
            continue

        if i == goal:
            return m

        pset.remove(i)

        for j in pset:
            dij = d2mat[i][j]
            mj = max(m, dij)
            if d[j] > mj:
                d[j] = mj
                heappush(hq, (mj, j))
    return d[goal]


def solve(n, ps):
    ans = dij(n, ps)
    a2 = math.sqrt(ans)
    c = math.ceil(a2 / 10)

    return min(filter(lambda a: (a * 10) ** 2 >= ans, [c - 1, c, c + 1])) * 10


def main():
    n = int(input())
    ps = []
    for i in range(n):
        x, y = list(map(int, input().split()))
        ps.append((x, y))
    print(solve(n, ps))


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