結果

問題 No.94 圏外です。(EASY)
ユーザー uafr_csuafr_cs
提出日時 2015-09-10 03:13:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 1,745 bytes
コンパイル時間 4,545 ms
コンパイル使用メモリ 79,716 KB
実行使用メモリ 59,508 KB
最終ジャッジ日時 2023-09-08 14:37:53
合計ジャッジ時間 7,555 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,048 KB
testcase_01 AC 123 ms
55,908 KB
testcase_02 AC 124 ms
55,648 KB
testcase_03 AC 121 ms
56,020 KB
testcase_04 AC 143 ms
56,264 KB
testcase_05 AC 184 ms
56,556 KB
testcase_06 AC 195 ms
56,900 KB
testcase_07 AC 206 ms
56,912 KB
testcase_08 AC 215 ms
58,920 KB
testcase_09 AC 244 ms
59,456 KB
testcase_10 AC 240 ms
58,908 KB
testcase_11 AC 233 ms
59,320 KB
testcase_12 AC 243 ms
59,440 KB
testcase_13 AC 247 ms
58,816 KB
testcase_14 AC 247 ms
59,304 KB
testcase_15 AC 248 ms
58,852 KB
testcase_16 AC 247 ms
58,660 KB
testcase_17 AC 247 ms
59,508 KB
testcase_18 AC 245 ms
59,044 KB
testcase_19 AC 260 ms
58,608 KB
testcase_20 AC 132 ms
56,168 KB
testcase_21 AC 124 ms
56,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static class UnionFind {
		int[] par;
		
		public UnionFind(int n) {
			par = new int[n];
			for(int i = 0; i < n; i++){
				par[i] = i;
			}
		}
		
		public int find(int x){
			if(par[x] == x){
				return x;
			}else{
				return par[x] = find(par[x]);
			}
		}
		
		public boolean same(int x, int y){
			return find(x) == find(y);
		}
		
		public boolean union(int x, int y){
			final int x_root = find(x);
			final int y_root = find(y);
			if(x_root == y_root){ return false; }
			
			par[y_root] = x_root;
			return true;
		}
		
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] xs = new int[N];
		int[] ys = new int[N];
		
		for(int i = 0; i < N; i++){
			xs[i] = sc.nextInt();
			ys[i] = sc.nextInt();
		}
		
		UnionFind uf = new UnionFind(N);
		
		for(int fst = 0; fst < N; fst++){
			for(int snd = fst + 1; snd < N; snd++){
				final int x_diff_2 = (xs[snd] - xs[fst]) * (xs[snd] - xs[fst]);
				final int y_diff_2 = (ys[snd] - ys[fst]) * (ys[snd] - ys[fst]);
				
				if(x_diff_2 + y_diff_2 <= 100){
					uf.union(fst, snd);
				}
			}
		}
		
		//System.out.println(Arrays.toString(uf.par));
		
		double max = N == 0 ? 1 : 2;
		for(int fst = 0; fst < N; fst++){
			for(int snd = fst + 1; snd < N; snd++){
				if(uf.same(fst, snd)){
					final int x_diff_2 = (xs[snd] - xs[fst]) * (xs[snd] - xs[fst]);
					final int y_diff_2 = (ys[snd] - ys[fst]) * (ys[snd] - ys[fst]);
					
					max = Math.max(max, Math.sqrt(x_diff_2 + y_diff_2) + 2);
				}
			}
		}
		
		System.out.printf("%.10f\n", max);
		
	}

}
0