結果

問題 No.168 ものさし
ユーザー 37zigen37zigen
提出日時 2016-03-25 16:28:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,432 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 72,820 KB
最終ジャッジ日時 2024-04-09 23:52:57
合計ジャッジ時間 13,390 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder168;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] x=new long[n];
		long[] y=new long[n];
		for(int i=0;i<n;i++){
			x[i]=sc.nextLong();
			y[i]=sc.nextLong();
		}

		long upper=200000000L;
		long low=0L;
		while(upper!=low&&upper!=low+1){
			System.err.println("upper "+upper);
			System.err.println("low "+low);
			long mid=(upper+low)/2;
			DJSet ds=new DJSet(n);
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(i==j)continue;
					if(Math.abs(x[i]-x[j])<=mid*10L&&Math.abs(y[i]-y[j])<=mid*10L){
						long len2=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
						System.err.println("len="+Math.sqrt(len2));
						if(len2<=mid*mid*100L){
							ds.setUnion(i, j);
						}
					}
				}
			}
			if(ds.setUnion(0,n-1)==false){
				upper=mid;
			}else{
				low=mid;
			}
		}
		System.out.println(low*10);
		sc.close();
	}
	public static class DJSet{
		int[] f;
		public DJSet(int size){
			f=new int[size];
			Arrays.fill(f, -1);
		}
		boolean setUnion(int x,int y){
			x=root(x);
			y=root(y);
			if(x!=y){
				if(f[x]>f[y]){
					int d=x;
					x=y;
					y=d;
				}
				f[x]+=f[y];
				f[y]=x;
			}
			return x!=y;
		}
		int root(int x){
			return f[x]<0?x:root(f[x]);
		}
		int count(){
			int cnt=0;
			for(int d:f){
				if(d<0)cnt++;
			}
			return cnt;
		}
	}
}

0