結果
| 問題 |
No.96 圏外です。
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2019-12-06 08:40:17 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,025 bytes |
| コンパイル時間 | 2,911 ms |
| コンパイル使用メモリ | 81,460 KB |
| 実行使用メモリ | 138,868 KB |
| 最終ジャッジ日時 | 2024-12-23 04:59:07 |
| 合計ジャッジ時間 | 48,307 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 TLE * 4 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n == 0) {
System.out.println(1);
return;
}
Point[] points = new Point[n];
for (int i = 0; i < n; i++) {
points[i] = new Point(sc.nextInt(), sc.nextInt());
}
Arrays.sort(points);
UnionFindTree uft = new UnionFindTree(n);
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (points[j].x - points[i].x > 10) {
break;
}
if (points[i].distance2(points[j]) <= 100) {
uft.unite(i, j);
}
}
}
long max = 0;
HashMap<Integer, ArrayList<Integer>> map = uft.getMap();
for (ArrayList<Integer> list : map.values()) {
for (int i = 0; i < list.size() - 1; i++) {
for (int j = i + 1; j < list.size(); j++) {
max = Math.max(max, points[list.get(i)].distance2(points[list.get(j)]));
}
}
}
System.out.println(Math.sqrt(max) + 2);
}
static class UnionFindTree {
int[] parents;
public UnionFindTree(int size) {
parents = new int[size];
for (int i = 0; i < size; i++) {
parents[i] = i;
}
}
public int find(int x) {
if (x == parents[x]) {
return x;
} else {
return parents[x] = find(parents[x]);
}
}
public void unite(int x, int y) {
int xx = find(x);
int yy = find(y);
if (xx == yy) {
return;
}
parents[xx] = yy;
}
public HashMap<Integer, ArrayList<Integer>> getMap() {
HashMap<Integer, ArrayList<Integer>> ret = new HashMap<>();
for (int i = 0; i < parents.length; i++) {
int x = find(i);
if (ret.containsKey(x)) {
ret.get(x).add(i);
} else {
ArrayList<Integer> list = new ArrayList<>();
list.add(i);
ret.put(x, list);
}
}
return ret;
}
public String toString() {
StringBuilder sb = new StringBuilder();
for (int x : parents) {
sb.append(x).append(" ");
}
return sb.toString();
}
}
static class Point implements Comparable<Point> {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int compareTo(Point another) {
if (x == another.x) {
return y - another.y;
} else {
return x - another.x;
}
}
public long distance2(Point another) {
return ((long)x - another.x) * ((long)x - another.x) + ((long)y - another.y) * ((long)y - another.y);
}
}
}
htensai