結果

問題 No.168 ものさし
ユーザー GrenacheGrenache
提出日時 2016-05-25 20:07:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 803 ms / 2,000 ms
コード長 2,349 bytes
コンパイル時間 3,737 ms
コンパイル使用メモリ 77,248 KB
実行使用メモリ 80,728 KB
最終ジャッジ日時 2023-08-25 21:01:31
合計ジャッジ時間 12,752 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 365 ms
64,912 KB
testcase_01 AC 124 ms
56,220 KB
testcase_02 AC 124 ms
56,420 KB
testcase_03 AC 122 ms
55,960 KB
testcase_04 AC 123 ms
55,480 KB
testcase_05 AC 124 ms
56,160 KB
testcase_06 AC 128 ms
55,520 KB
testcase_07 AC 125 ms
55,820 KB
testcase_08 AC 124 ms
56,100 KB
testcase_09 AC 149 ms
56,192 KB
testcase_10 AC 204 ms
57,652 KB
testcase_11 AC 364 ms
60,760 KB
testcase_12 AC 625 ms
70,192 KB
testcase_13 AC 803 ms
80,576 KB
testcase_14 AC 778 ms
80,728 KB
testcase_15 AC 126 ms
55,728 KB
testcase_16 AC 145 ms
56,312 KB
testcase_17 AC 160 ms
55,972 KB
testcase_18 AC 230 ms
58,372 KB
testcase_19 AC 729 ms
80,588 KB
testcase_20 AC 773 ms
80,196 KB
testcase_21 AC 750 ms
80,608 KB
testcase_22 AC 752 ms
80,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


public class Main_yukicoder168 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
        	x[i] = sc.nextInt();
        	y[i] = sc.nextInt();
        }

        List<Tri> p = new ArrayList<>();
        for (int i = 0; i < n; i++) {
        	for (int j = i + 1; j < n; j++) {
        		long d = (long)(x[i] - x[j]) * (x[i] - x[j]) + (long)(y[i] - y[j]) * (y[i] - y[j]);
        		p.add(new Tri(i, j, d));
        	}
        }
        Collections.sort(p);

        UnionFind uf = new UnionFind(n);
        long min = Long.MAX_VALUE;
        for (Tri e : p) {
        	uf.union(e.i, e.j);
        	if (uf.same(0, n - 1)) {
        		min = e.d;
        		break;
        	}
        }

        long l = 0;
        long r = 200_000_000;
        for (int i = 0; i < 100; i++) {
        	long mid = l + (r - l) / 2;

        	long tmp = (mid * 10) * (mid * 10) - min;
        	if (tmp >= 0) {
        		r = mid;
        	} else {
        		l = mid;
        	}
        }

        System.out.println(r * 10);

        sc.close();
    }

    private static class Tri implements Comparable<Tri> {
    	int i;
    	int j;
    	long d;

    	Tri(int i, int j, long d) {
    		this.i = i;
    		this.j = j;
    		this.d = d;
    	}

		@Override
		public int compareTo(Tri o) {
			return Long.compare(this.d, o.d);
		}
    }

	@SuppressWarnings("unused")
	private static class UnionFind {
		int[] parent;
		int[] rank;

		UnionFind(int n) {
			parent = new int[n];
			rank = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
				rank[i] = 0;
			}
		}

		int find(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				return parent[x] = find(parent[x]);
			}
		}

		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		void union(int x, int y) {
			x = find(x);
			y = find(y);
			if (x != y) {
				if (rank[x] > rank[y]) {
					parent[y] = x;
				} else {
					parent[x] = y;
					if (rank[x] == rank[y]) {
						rank[y]++;
					}
				}
			}

			return;
		}

		// 異なる集合の数
		int count() {
			int ret = 0;
			for (int i = 0; i < parent.length; i++) {
				if (find(i) == i) {
					ret++;
				}
			}

			return ret;
		}
	}
}
0