結果

問題 No.168 ものさし
ユーザー H3PO4H3PO4
提出日時 2020-05-10 09:13:28
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,456 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 244,928 KB
最終ジャッジ日時 2023-09-21 10:29:33
合計ジャッジ時間 16,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 523 ms
106,800 KB
testcase_01 AC 100 ms
71,832 KB
testcase_02 AC 98 ms
71,616 KB
testcase_03 AC 100 ms
71,652 KB
testcase_04 AC 99 ms
71,872 KB
testcase_05 AC 99 ms
71,948 KB
testcase_06 AC 101 ms
71,752 KB
testcase_07 AC 104 ms
71,848 KB
testcase_08 AC 101 ms
71,472 KB
testcase_09 AC 133 ms
77,980 KB
testcase_10 AC 146 ms
79,212 KB
testcase_11 AC 242 ms
85,108 KB
testcase_12 AC 498 ms
98,552 KB
testcase_13 AC 656 ms
108,768 KB
testcase_14 AC 642 ms
108,736 KB
testcase_15 AC 100 ms
71,928 KB
testcase_16 AC 125 ms
77,764 KB
testcase_17 AC 143 ms
79,388 KB
testcase_18 AC 212 ms
84,452 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
from math import isqrt
from collections import defaultdict

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
        self.size = [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
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                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)]

d = defaultdict(list)
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)
    d[ceil(dist, 10) * 10].append((p1, p2))

lst = sorted(list(d.items()))
lst.sort()

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