結果
問題 | No.1265 Balloon Survival |
ユーザー | tenten |
提出日時 | 2023-02-16 18:07:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 529 ms / 2,000 ms |
コード長 | 3,196 bytes |
コンパイル時間 | 2,563 ms |
コンパイル使用メモリ | 98,920 KB |
実行使用メモリ | 69,548 KB |
最終ジャッジ日時 | 2024-07-18 18:02:09 |
合計ジャッジ時間 | 11,298 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
36,952 KB |
testcase_01 | AC | 46 ms
37,324 KB |
testcase_02 | AC | 46 ms
37,080 KB |
testcase_03 | AC | 48 ms
37,288 KB |
testcase_04 | AC | 47 ms
37,032 KB |
testcase_05 | AC | 49 ms
37,120 KB |
testcase_06 | AC | 46 ms
37,240 KB |
testcase_07 | AC | 49 ms
37,108 KB |
testcase_08 | AC | 46 ms
37,008 KB |
testcase_09 | AC | 47 ms
37,032 KB |
testcase_10 | AC | 47 ms
36,976 KB |
testcase_11 | AC | 46 ms
36,848 KB |
testcase_12 | AC | 48 ms
37,296 KB |
testcase_13 | AC | 47 ms
37,240 KB |
testcase_14 | AC | 158 ms
44,152 KB |
testcase_15 | AC | 141 ms
43,156 KB |
testcase_16 | AC | 99 ms
40,676 KB |
testcase_17 | AC | 367 ms
55,272 KB |
testcase_18 | AC | 111 ms
41,044 KB |
testcase_19 | AC | 103 ms
40,864 KB |
testcase_20 | AC | 146 ms
44,632 KB |
testcase_21 | AC | 243 ms
47,584 KB |
testcase_22 | AC | 186 ms
47,408 KB |
testcase_23 | AC | 195 ms
47,340 KB |
testcase_24 | AC | 529 ms
69,548 KB |
testcase_25 | AC | 477 ms
69,340 KB |
testcase_26 | AC | 471 ms
69,276 KB |
testcase_27 | AC | 476 ms
69,304 KB |
testcase_28 | AC | 466 ms
69,200 KB |
testcase_29 | AC | 494 ms
69,484 KB |
testcase_30 | AC | 479 ms
69,364 KB |
testcase_31 | AC | 457 ms
69,400 KB |
testcase_32 | AC | 466 ms
69,488 KB |
testcase_33 | AC | 473 ms
69,404 KB |
testcase_34 | AC | 48 ms
37,276 KB |
testcase_35 | AC | 46 ms
37,400 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); Point[] points = new Point[n]; ArrayList<Distance> distances = new ArrayList<>(); for (int i = 0; i < n; i++) { points[i] = new Point(sc.nextInt(), sc.nextInt()); for (int j = 0; j < i; j++) { distances.add(new Distance(j, i, points[i].getDistance(points[j]))); } } Collections.sort(distances); int ans = 0; boolean[] used = new boolean[n]; for (Distance x : distances) { if (x.left == 0) { if (!used[x.right]) { used[x.right] = true; ans++; } } else { if (!used[x.left] && !used[x.right]) { used[x.left] = true; used[x.right] = true; } } } System.out.println(ans); } static class Distance implements Comparable<Distance> { int left; int right; long value; public Distance(int left, int right, long value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Distance another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } static class Point { long x; long y; public Point(long x, long y) { this.x = x; this.y = y; } public long getDistance(Point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }