結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:31:22 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,369 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 82,832 KB |
| 実行使用メモリ | 147,348 KB |
| 最終ジャッジ日時 | 2025-03-20 20:32:32 |
| 合計ジャッジ時間 | 8,528 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 18 WA * 1 |
ソースコード
import math
class UnionFind:
def __init__(self, size):
self.parent = list(range(size))
def find(self, x):
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]] # Path compression
x = self.parent[x]
return x
def union(self, x, y):
x_root = self.find(x)
y_root = self.find(y)
if x_root == y_root:
return
self.parent[y_root] = x_root
def connected(self, x, y):
return self.find(x) == self.find(y)
n = int(input())
points = []
for _ in range(n):
x, y = map(int, input().split())
points.append((x, y))
if n == 0:
print(0)
exit()
s = 0
t = n - 1
edges = []
max_sq = 0
for i in range(n):
x1, y1 = points[i]
for j in range(i + 1, n):
x2, y2 = points[j]
dx = x1 - x2
dy = y1 - y2
sq = dx * dx + dy * dy
if sq > max_sq:
max_sq = sq
edges.append((i, j, sq))
left = 0
right = max_sq
answer_sq = max_sq
while left <= right:
mid_sq = (left + right) // 2
uf = UnionFind(n)
for i, j, sq in edges:
if sq <= mid_sq:
uf.union(i, j)
if uf.connected(s, t):
answer_sq = mid_sq
right = mid_sq - 1
else:
left = mid_sq + 1
d = math.sqrt(answer_sq)
L = math.ceil(d / 10) * 10
print(int(L))
lam6er