結果

問題 No.2179 Planet Traveler
ユーザー shobonvipshobonvip
提出日時 2023-01-06 22:10:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 360 ms / 3,000 ms
コード長 1,277 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 103,060 KB
最終ジャッジ日時 2023-08-20 15:20:40
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,188 KB
testcase_01 AC 76 ms
71,324 KB
testcase_02 AC 76 ms
71,308 KB
testcase_03 AC 77 ms
71,300 KB
testcase_04 AC 76 ms
71,192 KB
testcase_05 AC 75 ms
71,388 KB
testcase_06 AC 74 ms
71,424 KB
testcase_07 AC 83 ms
76,396 KB
testcase_08 AC 85 ms
76,340 KB
testcase_09 AC 89 ms
76,404 KB
testcase_10 AC 88 ms
76,580 KB
testcase_11 AC 181 ms
102,176 KB
testcase_12 AC 313 ms
101,840 KB
testcase_13 AC 356 ms
102,076 KB
testcase_14 AC 215 ms
103,060 KB
testcase_15 AC 192 ms
102,728 KB
testcase_16 AC 182 ms
101,804 KB
testcase_17 AC 354 ms
102,528 KB
testcase_18 AC 360 ms
102,532 KB
testcase_19 AC 345 ms
101,980 KB
testcase_20 AC 134 ms
79,808 KB
testcase_21 AC 341 ms
99,184 KB
testcase_22 AC 263 ms
91,992 KB
testcase_23 AC 225 ms
90,084 KB
testcase_24 AC 311 ms
96,164 KB
testcase_25 AC 258 ms
92,388 KB
testcase_26 AC 314 ms
99,364 KB
testcase_27 AC 124 ms
78,972 KB
testcase_28 AC 204 ms
87,088 KB
testcase_29 AC 311 ms
96,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n
	
	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]
	
	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			x, y = y, x
		self.parents[x] += self.parents[y]
		self.parents[y] = x

n = int(input())
x = [0] * n
y = [0] * n
t = [0] * n
uf = UnionFind(n)

for i in range(n):
	x[i], y[i], t[i] = map(int,input().split())

a = []
dist = 0
for i in range(n):
	for j in range(i+1, n):
		if t[i] == t[j]:
			dist = (x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2
		else:
			p2 = x[i] ** 2 + y[i] ** 2
			q2 = x[j] ** 2 + y[j] ** 2
			p2, q2 = min(p2, q2), max(p2, q2)
			suki = 10 ** 12
			kirai = -1
			while suki - kirai > 1:
				targ = (suki + kirai) // 2
				tmp = q2 - p2 - targ
				if tmp <= 0 or tmp * tmp <= 4 * targ * p2:
					suki = targ
				else:
					kirai = targ
			dist = suki
			#print(dist)
		a.append((dist << 30) + (i << 15) + j)

a.sort()
mask = (1 << 15) - 1
ans = 0
for v in a:
	dist = v >> 30
	i = (v >> 15) & mask
	j = v & mask
	ans = dist
	#print(dist, i, j)
	uf.union(i, j)
	if uf.find(0) == uf.find(n-1):
		break

print(ans)
0