結果

問題 No.168 ものさし
ユーザー take4yotake4yo
提出日時 2020-09-18 23:48:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 1,453 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 77,172 KB
最終ジャッジ日時 2023-09-04 12:10:48
合計ジャッジ時間 3,652 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
76,416 KB
testcase_01 AC 75 ms
71,208 KB
testcase_02 AC 76 ms
71,204 KB
testcase_03 AC 75 ms
71,212 KB
testcase_04 AC 76 ms
71,216 KB
testcase_05 AC 77 ms
71,184 KB
testcase_06 AC 76 ms
71,180 KB
testcase_07 AC 77 ms
71,056 KB
testcase_08 AC 76 ms
71,316 KB
testcase_09 AC 85 ms
75,912 KB
testcase_10 AC 95 ms
75,484 KB
testcase_11 AC 103 ms
76,260 KB
testcase_12 AC 120 ms
76,168 KB
testcase_13 AC 127 ms
76,860 KB
testcase_14 AC 100 ms
75,964 KB
testcase_15 AC 75 ms
71,204 KB
testcase_16 AC 88 ms
75,784 KB
testcase_17 AC 93 ms
75,608 KB
testcase_18 AC 95 ms
75,716 KB
testcase_19 AC 128 ms
76,876 KB
testcase_20 AC 111 ms
75,984 KB
testcase_21 AC 126 ms
77,172 KB
testcase_22 AC 112 ms
76,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N = int(input())
MAXDIST = 9*10**18 + 1

pos = []
for i in range(N):
    x, y = map(int, input().split())
    pos.append((x, y))

def distance(a, b):
    x0, y0 = pos[a]
    x1, y1 = pos[b]
    dd = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0)
    return math.sqrt(dd)
    #return dd

def distance2(a, b):
    x0, y0 = pos[a]
    x1, y1 = pos[b]
    dd = (x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0)
    #return math.sqrt(dd)
    return dd

def prim():
    parent = [-1]*(N+1)
    intree = [0]*(N+1)
    dist = [MAXDIST]*(N+1)


    src = 0
    dist[src] = 0
    while src >= 0 and src != N-1:
        intree[src] = 1
        mind = MAXDIST
        nxt = -1
        for k in range(N):
            if intree[k] == 0:
                dd = distance2(src, k)
                if dist[k] > max(dist[src], dd):
                    dist[k] = max(dist[src], dd)
                    parent[k] = src
                if dist[k] < mind:
                    mind = dist[k]
                    nxt = k
        #if nxt >= 0: parent[nxt] = src
        src = nxt

    if src < 0: #not found??
        return MAXDIST

    return dist[N-1]
    # #find max
    # ans = 0
    # while src != 0:
    #     pp = parent[src]
    #     dd = distance2(src, pp)
    #     if ans < dd:
    #         ans = dd
    #
    #     src = pp
    #
    # return ans

prm = prim()
ans = int(math.sqrt(prm))
while ans*ans < prm:
    ans = ans + 1

ans = math.ceil(ans/10) * 10
print(ans)
0