結果

問題 No.168 ものさし
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-07 05:28:38
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,543 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 174,592 KB
最終ジャッジ日時 2024-04-25 08:58:12
合計ジャッジ時間 16,366 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 461 ms
94,336 KB
testcase_01 AC 40 ms
51,968 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 41 ms
52,224 KB
testcase_04 AC 41 ms
52,480 KB
testcase_05 AC 38 ms
52,224 KB
testcase_06 AC 46 ms
57,856 KB
testcase_07 AC 41 ms
52,224 KB
testcase_08 AC 42 ms
52,352 KB
testcase_09 AC 85 ms
71,808 KB
testcase_10 AC 109 ms
76,544 KB
testcase_11 AC 396 ms
93,056 KB
testcase_12 AC 1,319 ms
142,208 KB
testcase_13 AC 1,811 ms
172,416 KB
testcase_14 AC 1,847 ms
173,824 KB
testcase_15 AC 41 ms
52,608 KB
testcase_16 AC 67 ms
67,968 KB
testcase_17 AC 99 ms
76,672 KB
testcase_18 AC 146 ms
79,104 KB
testcase_19 AC 1,969 ms
171,392 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10**18


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        self.root[x] = self.find(self.root[x])
        return self.root[x]

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return True

    def size(self, x):
        return -self.root[self.find(x)]


def length(dx, dy):
    dist = dx * dx + dy * dy
    l = 0
    r = 10 ** 10
    while r - l > 1:
        m = (l + r) // 2
        if m * m * 100 >= dist:
            r = m
        else:
            l = m
    return r * 10


N = int(input())
XY = tuple(tuple(map(int, input().split())) for _ in range(N))
edge = []
G = [[0] * N for _ in range(N)]
for i in range(N):
    x, y = XY[i]
    for j in range(i + 1, N):
        xx, yy = XY[j]
        ruler = length(abs(xx - x), abs(yy - y))
        edge.append((ruler, i, j))
edge.sort()

uf = UF_tree(N)
for L, x, y in edge:
    uf.unite(x, y)
    if uf.isSame(0, N - 1):
        break
print(L)
0