結果

問題 No.1265 Balloon Survival
ユーザー ks2mks2m
提出日時 2020-10-23 22:29:45
言語 Java19
(openjdk 21)
結果
AC  
実行時間 757 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 3,748 ms
コンパイル使用メモリ 78,660 KB
実行使用メモリ 80,904 KB
最終ジャッジ日時 2023-09-28 16:36:09
合計ジャッジ時間 17,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,960 KB
testcase_01 AC 132 ms
55,836 KB
testcase_02 AC 134 ms
55,820 KB
testcase_03 AC 136 ms
53,756 KB
testcase_04 AC 137 ms
55,536 KB
testcase_05 AC 139 ms
56,172 KB
testcase_06 AC 136 ms
55,956 KB
testcase_07 AC 136 ms
55,692 KB
testcase_08 AC 136 ms
55,820 KB
testcase_09 AC 135 ms
55,752 KB
testcase_10 AC 136 ms
55,568 KB
testcase_11 AC 137 ms
56,156 KB
testcase_12 AC 138 ms
55,648 KB
testcase_13 AC 136 ms
55,520 KB
testcase_14 AC 316 ms
59,484 KB
testcase_15 AC 293 ms
59,060 KB
testcase_16 AC 224 ms
58,060 KB
testcase_17 AC 474 ms
66,120 KB
testcase_18 AC 239 ms
58,284 KB
testcase_19 AC 226 ms
57,764 KB
testcase_20 AC 305 ms
59,552 KB
testcase_21 AC 356 ms
63,952 KB
testcase_22 AC 324 ms
59,308 KB
testcase_23 AC 314 ms
59,492 KB
testcase_24 AC 733 ms
79,284 KB
testcase_25 AC 727 ms
80,796 KB
testcase_26 AC 709 ms
80,792 KB
testcase_27 AC 746 ms
80,564 KB
testcase_28 AC 757 ms
80,784 KB
testcase_29 AC 749 ms
80,904 KB
testcase_30 AC 733 ms
80,356 KB
testcase_31 AC 719 ms
80,688 KB
testcase_32 AC 702 ms
80,384 KB
testcase_33 AC 742 ms
80,772 KB
testcase_34 AC 145 ms
55,920 KB
testcase_35 AC 135 ms
55,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		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();
		}
		sc.close();

		PriorityQueue<Obj> que = new PriorityQueue<>((o1, o2) -> Long.compare(o1.d, o2.d));
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				Obj o = new Obj();
				o.a = i;
				o.b = j;
				long dx = x[i] - x[j];
				long dy = y[i] - y[j];
				o.d = dx * dx + dy * dy;
				que.add(o);
			}
		}

		int ans = 0;
		boolean[] used = new boolean[n];
		while (!que.isEmpty()) {
			Obj o = que.poll();
			if (used[o.a] || used[o.b]) {
				continue;
			}
			if (o.a != 0 && o.b != 0) {
				used[o.a] = true;
				used[o.b] = true;
			} else {
				int c = o.a;
				if (c == 0) {
					c = o.b;
				}
				used[c] = true;
				ans++;
			}
		}
		System.out.println(ans);
	}

	static class Obj {
		int a, b;
		long d;
	}
}
0