結果

問題 No.168 ものさし
ユーザー roarisroaris
提出日時 2019-10-30 15:07:22
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 98,964 KB
最終ジャッジ日時 2023-10-12 23:47:22
合計ジャッジ時間 10,765 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,840 ms
98,964 KB
testcase_01 AC 75 ms
71,256 KB
testcase_02 AC 74 ms
71,152 KB
testcase_03 AC 73 ms
71,156 KB
testcase_04 AC 72 ms
71,352 KB
testcase_05 AC 74 ms
71,508 KB
testcase_06 AC 81 ms
75,820 KB
testcase_07 AC 74 ms
71,228 KB
testcase_08 AC 75 ms
71,336 KB
testcase_09 AC 173 ms
77,924 KB
testcase_10 AC 308 ms
79,308 KB
testcase_11 AC 1,855 ms
94,272 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Unionfind():
    def __init__(self, n):
        self.par = [-1] * n
        self.rank = [1] * n
    
    def root(self, x):
        if self.par[x] < 0:
            return x
        
        self.par[x] = self.root(self.par[x])
        
        return self.par[x]
    
    def unite(self, x, y):
        rx, ry = self.root(x), self.root(y)
        
        if rx != ry:
            if self.rank[rx] >= self.rank[ry]:
                self.par[rx] += self.par[ry]
                self.par[ry] = rx
                
                if self.rank[rx] == self.rank[ry]:
                    self.rank[rx] += 1
            else:
                self.par[ry] += self.par[rx]
                self.par[rx] = ry
    
    def is_same(self, x, y):
        return self.root(x) == self.root(y)
    
    def count(self, x):
        return -self.par[x]

def isOk(x):
    uf = Unionfind(N)
    
    for s, t, w in square_edges:
        if w <= (10*x)**2:
            uf.unite(s, t)
        else:
            break
    
    return uf.is_same(0, N-1)
    
N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
square_edges = []

for i in range(N):
    for j in range(i+1, N):
        Xi, Yi = XY[i]
        Xj, Yj = XY[j]
        square_edges.append((i, j, (Xi-Xj)**2+(Yi-Yj)**2))

square_edges.sort(key=lambda k: k[2])
ng, ok = -1, 10**11

while abs(ok-ng) > 1:
    mid = (ng+ok)//2
    
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(10*ok)
0