結果

問題 No.94 圏外です。(EASY)
ユーザー lam6er
提出日時 2025-03-26 15:45:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 5,000 ms
コード長 1,933 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 76,788 KB
最終ジャッジ日時 2025-03-26 15:45:12
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import math
from collections import defaultdict
class UnionFind:
def __init__(self, size):
self.parent = list(range(size))
self.rank = [0] * size
def find(self, x):
if self.parent[x] != x:
self.parent[x] = self.find(self.parent[x])
return self.parent[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] < self.rank[y]:
self.parent[x] = y
else:
self.parent[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
def main():
N = int(input())
points = []
for _ in range(N):
x, y = map(int, input().split())
points.append((x, y))
if N == 0:
print(1.0)
return
uf = UnionFind(N)
for i in range(N):
for j in range(i + 1, N):
x1, y1 = points[i]
x2, y2 = points[j]
dx = x1 - x2
dy = y1 - y2
if dx * dx + dy * dy <= 100: # 10^2
uf.unite(i, j)
groups = defaultdict(list)
for i in range(N):
root = uf.find(i)
groups[root].append(points[i])
max_candidate = 0.0
for group in groups.values():
max_dist_sq = 0
n = len(group)
for i in range(n):
x1, y1 = group[i]
for j in range(i + 1, n):
x2, y2 = group[j]
dx = x1 - x2
dy = y1 - y2
dist_sq = dx * dx + dy * dy
if dist_sq > max_dist_sq:
max_dist_sq = dist_sq
max_dist = math.sqrt(max_dist_sq) if max_dist_sq > 0 else 0.0
candidate = max_dist + 2.0
if candidate > max_candidate:
max_candidate = candidate
ans = max(max_candidate, 1.0)
print("{0:.9f}".format(ans))
if __name__ == "__main__":
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0