結果
問題 | No.168 ものさし |
ユーザー | htensai |
提出日時 | 2020-01-15 17:51:28 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 346 ms / 2,000 ms |
コード長 | 2,179 bytes |
コンパイル時間 | 2,796 ms |
コンパイル使用メモリ | 74,092 KB |
実行使用メモリ | 64,240 KB |
最終ジャッジ日時 | 2023-09-02 01:21:49 |
合計ジャッジ時間 | 8,807 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge16 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 250 ms
58,824 KB |
testcase_01 | AC | 119 ms
56,096 KB |
testcase_02 | AC | 119 ms
56,176 KB |
testcase_03 | AC | 120 ms
55,824 KB |
testcase_04 | AC | 117 ms
56,132 KB |
testcase_05 | AC | 121 ms
56,248 KB |
testcase_06 | AC | 122 ms
56,056 KB |
testcase_07 | AC | 118 ms
56,384 KB |
testcase_08 | AC | 118 ms
56,092 KB |
testcase_09 | AC | 138 ms
56,264 KB |
testcase_10 | AC | 155 ms
56,232 KB |
testcase_11 | AC | 215 ms
59,052 KB |
testcase_12 | AC | 282 ms
63,796 KB |
testcase_13 | AC | 306 ms
64,240 KB |
testcase_14 | AC | 298 ms
64,184 KB |
testcase_15 | AC | 122 ms
56,016 KB |
testcase_16 | AC | 142 ms
55,840 KB |
testcase_17 | AC | 173 ms
56,376 KB |
testcase_18 | AC | 193 ms
56,720 KB |
testcase_19 | AC | 346 ms
64,032 KB |
testcase_20 | AC | 341 ms
63,992 KB |
testcase_21 | AC | 319 ms
63,836 KB |
testcase_22 | AC | 307 ms
64,236 KB |
ソースコード
import java.util.*; import java.math.*; public class Main { static int[] base; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] xArr = new int[n]; int[] yArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); } long[][] sizes = new long[n][n]; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { sizes[i][j] = getSize(xArr[i], yArr[i], xArr[j], yArr[j]); } } long left = 0; long right = (int)(Math.sqrt(sizes[0][n - 1]) / 10 + 1); while (right - left > 1) { long m = (left + right) / 2; UnionFindTree uft = new UnionFindTree(n); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if ((m * 10) * (m * 10) >= sizes[i][j]) { uft.unite(i, j); } } } if (uft.same()) { right = m; } else { left = m; } } System.out.println(right * 10); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (parents[x] == x) { return x; } else { return parents[x] = find(parents[x]); } } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } parents[xx] = yy; } public boolean same() { return find(0) == find(parents.length - 1); } } static long getSize(long x1, long y1, long x2, long y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } }