結果

問題 No.168 ものさし
ユーザー H3PO4H3PO4
提出日時 2020-05-10 09:41:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,246 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 62,216 KB
最終ジャッジ日時 2023-09-21 11:03:44
合計ジャッジ時間 9,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
20,672 KB
testcase_01 AC 16 ms
8,536 KB
testcase_02 AC 16 ms
8,540 KB
testcase_03 AC 16 ms
8,496 KB
testcase_04 AC 17 ms
8,552 KB
testcase_05 AC 16 ms
8,540 KB
testcase_06 AC 16 ms
8,396 KB
testcase_07 AC 16 ms
8,380 KB
testcase_08 AC 16 ms
8,544 KB
testcase_09 AC 21 ms
8,912 KB
testcase_10 AC 37 ms
9,748 KB
testcase_11 AC 208 ms
19,224 KB
testcase_12 AC 771 ms
45,584 KB
testcase_13 AC 1,122 ms
61,544 KB
testcase_14 AC 1,097 ms
62,212 KB
testcase_15 AC 17 ms
8,396 KB
testcase_16 AC 20 ms
8,784 KB
testcase_17 AC 29 ms
9,140 KB
testcase_18 AC 60 ms
10,924 KB
testcase_19 AC 1,147 ms
60,232 KB
testcase_20 AC 1,175 ms
61,852 KB
testcase_21 AC 1,246 ms
62,216 KB
testcase_22 AC 1,197 ms
61,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
from math import isqrt
import sys
input = sys.stdin.readline

ceil = lambda a, b: (a + b - 1) // b
ceil_sq = lambda n: 1 + isqrt(n - 1)


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.height = [1] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.height[x] < self.height[y]:
                self.parent[x] = y
            else:
                self.parent[y] = x
                if self.height[x] == self.height[y]:
                    self.height[x] += 1

    def issame(self, x, y):
        return self.find(x) == self.find(y)


N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]

lst = []
for p1, p2 in itertools.combinations(range(N), 2):
    dist = ceil_sq((P[p1][0] - P[p2][0]) ** 2 + (P[p1][1] - P[p2][1]) ** 2)
    lst.append((ceil(dist, 10) * 10, p1, p2))
lst.sort()

uf = UnionFind(N)
for dist, p1, p2 in lst:
    uf.unite(p1, p2)
    if uf.issame(0, N - 1):
        print(dist)
        break
0