結果
| 問題 |
No.168 ものさし
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-03-25 16:30:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 568 ms / 2,000 ms |
| コード長 | 1,388 bytes |
| コンパイル時間 | 2,343 ms |
| コンパイル使用メモリ | 78,100 KB |
| 実行使用メモリ | 45,260 KB |
| 最終ジャッジ日時 | 2024-12-24 07:13:31 |
| 合計ジャッジ時間 | 9,055 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
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]);
if(len2<=mid*mid*100L){
ds.setUnion(i, j);
}
}
}
}
if(ds.setUnion(0,n-1)==false){
upper=mid;
}else{
low=mid;
}
}
System.out.println(upper*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;
}
}
}