結果

問題 No.96 圏外です。
ユーザー htensaihtensai
提出日時 2019-12-06 08:40:17
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 3,025 bytes
コンパイル時間 3,348 ms
コンパイル使用メモリ 81,932 KB
実行使用メモリ 84,708 KB
最終ジャッジ日時 2023-08-24 19:43:41
合計ジャッジ時間 25,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,032 KB
testcase_01 AC 122 ms
55,960 KB
testcase_02 AC 122 ms
56,320 KB
testcase_03 AC 120 ms
55,564 KB
testcase_04 AC 231 ms
59,312 KB
testcase_05 AC 261 ms
58,012 KB
testcase_06 AC 310 ms
60,892 KB
testcase_07 AC 362 ms
60,688 KB
testcase_08 AC 417 ms
62,348 KB
testcase_09 AC 457 ms
60,688 KB
testcase_10 AC 572 ms
64,568 KB
testcase_11 AC 613 ms
66,568 KB
testcase_12 AC 643 ms
65,404 KB
testcase_13 AC 906 ms
69,556 KB
testcase_14 AC 941 ms
71,956 KB
testcase_15 AC 1,080 ms
69,524 KB
testcase_16 AC 1,128 ms
74,232 KB
testcase_17 AC 1,105 ms
83,684 KB
testcase_18 AC 1,225 ms
84,708 KB
testcase_19 AC 1,241 ms
78,752 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
       }
   }
   
}

0