結果

問題 No.168 ものさし
ユーザー roarisroaris
提出日時 2019-10-30 15:10:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 10,752 KB
実行使用メモリ 67,632 KB
最終ジャッジ日時 2023-10-12 23:47:48
合計ジャッジ時間 8,884 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,211 ms
30,456 KB
testcase_01 AC 16 ms
8,104 KB
testcase_02 AC 16 ms
8,040 KB
testcase_03 AC 16 ms
8,152 KB
testcase_04 AC 16 ms
8,020 KB
testcase_05 AC 17 ms
8,044 KB
testcase_06 AC 17 ms
8,044 KB
testcase_07 AC 16 ms
8,072 KB
testcase_08 AC 16 ms
8,036 KB
testcase_09 AC 62 ms
8,756 KB
testcase_10 AC 215 ms
9,840 KB
testcase_11 TLE -
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