結果
問題 | No.168 ものさし |
ユーザー |
![]() |
提出日時 | 2019-07-21 13:46:43 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 406 ms / 2,000 ms |
コード長 | 1,581 bytes |
コンパイル時間 | 3,456 ms |
コンパイル使用メモリ | 77,216 KB |
実行使用メモリ | 57,760 KB |
最終ジャッジ日時 | 2024-06-12 04:10:58 |
合計ジャッジ時間 | 8,088 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 |
ソースコード
import java.util.*; public class Main { static int[] par; static int[] rank; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); par = new int[n]; rank = new int[n]; 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(); } init(n); long l = 0; long r = (long)Math.pow(10, 10); long ans = 0; while(l < r) { long med = (l + r) / 2; for(int i = 0; i < n - 1; i++) { for(int j = i + 1; j < n; j++) { if(((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) <= med * med) unite(i, j); } } if(same(0, n - 1)) { ans = med; r = med; } else { l = med + 1; } init(n); } for(int i = 0; i < 10; i++) { if(ans % 10 == 0) break; ans++; } System.out.println(ans); } static void init(int m) { for(int i = 0; i < m; i++) { par[i] = i; rank[i] = 0; } } static int find(int x) { if(par[x] == x) { return x; } else { return par[x] = find(par[x]); } } static void unite(int x, int y) { x = find(x); y = find(y); if(x != y) { if(rank[x] < rank[y]) { par[x] = y; } else { par[y] = x; if(rank[x] == rank[y]) { rank[x]++; } } } } static boolean same(int x, int y) { return find(x) == find(y); } }