結果
問題 |
No.168 ものさし
|
ユーザー |
|
提出日時 | 2016-03-25 15:54:36 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,341 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 79,936 KB |
実行使用メモリ | 60,612 KB |
最終ジャッジ日時 | 2024-10-02 00:49:04 |
合計ジャッジ時間 | 9,400 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 6 WA * 13 |
ソースコード
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=200000000; long low=0; 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*10&&Math.abs(y[i]-y[j])<=mid*10){ if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=mid*mid*100){ ds.setUnion(i, j); } } } } if(ds.count()==1){ upper=mid; }else{ low=mid; } } System.out.println(upper*10); sc.close(); } static class DJSet{ int[] d; DJSet(int size){ d=new int[size]; Arrays.fill(d, -1); } boolean setUnion(int x,int y){ x=root(x); y=root(y); if(x!=y){ if(d[x]<d[y]){ int tmp=y; y=x; x=tmp; } d[y]+=d[x]; d[x]=y; } return x!=y; } int root(int x){ return d[x]<0?x:(d[x]=root(d[x])); } int count(){ int cnt=0; for(int a:d){ if(a<0)cnt++; } return cnt; } } }