結果

問題 No.2179 Planet Traveler
ユーザー rlangevinrlangevin
提出日時 2023-03-19 00:15:12
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,591 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,076 KB
実行使用メモリ 78,196 KB
最終ジャッジ日時 2023-10-18 17:37:32
合計ジャッジ時間 16,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
54,044 KB
testcase_01 AC 39 ms
53,980 KB
testcase_02 AC 37 ms
54,044 KB
testcase_03 AC 38 ms
53,980 KB
testcase_04 AC 39 ms
54,044 KB
testcase_05 AC 37 ms
54,044 KB
testcase_06 AC 38 ms
53,980 KB
testcase_07 AC 55 ms
67,008 KB
testcase_08 AC 93 ms
76,524 KB
testcase_09 AC 99 ms
76,596 KB
testcase_10 AC 87 ms
76,524 KB
testcase_11 AC 435 ms
77,444 KB
testcase_12 AC 1,083 ms
77,700 KB
testcase_13 WA -
testcase_14 AC 404 ms
77,916 KB
testcase_15 AC 404 ms
77,892 KB
testcase_16 AC 403 ms
77,804 KB
testcase_17 AC 1,039 ms
77,328 KB
testcase_18 AC 1,051 ms
77,588 KB
testcase_19 AC 1,061 ms
77,588 KB
testcase_20 AC 248 ms
77,404 KB
testcase_21 AC 971 ms
77,588 KB
testcase_22 AC 681 ms
77,784 KB
testcase_23 AC 614 ms
77,256 KB
testcase_24 AC 872 ms
77,200 KB
testcase_25 AC 713 ms
77,324 KB
testcase_26 AC 960 ms
77,480 KB
testcase_27 AC 252 ms
77,320 KB
testcase_28 AC 513 ms
77,324 KB
testcase_29 AC 952 ms
78,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

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

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

def dist1(i, j):
    return (X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2

def dist2(i, j):
    return abs(sqrt(X[i] ** 2 + Y[i] ** 2) - sqrt(X[j] ** 2  + Y[j] ** 2))

N = int(input())
X, Y, T = [0] * N, [0] * N, [0] * N
for i in range(N):
    X[i], Y[i], T[i] = map(int, input().split())
    
yes = 10 ** 18 + 5
no = -1
eps = 10**-10
while yes - no != 1:
    mid = (yes + no)//2
    U = UnionFind(N)
    for i in range(N):
        for j in range(i + 1, N):
            if T[i] != T[j]:
                if dist2(i, j) ** 2 - eps <= mid:
                    U.union(i, j)
            else:
                if dist1(i, j) <= mid:
                    U.union(i, j)
    if U.is_same(0, N - 1):
        yes = mid
    else:
        no = mid
        
print(yes)
0