結果
問題 | No.1265 Balloon Survival |
ユーザー | tenten |
提出日時 | 2024-02-07 08:34:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 718 ms / 2,000 ms |
コード長 | 2,896 bytes |
コンパイル時間 | 2,857 ms |
コンパイル使用メモリ | 87,488 KB |
実行使用メモリ | 80,504 KB |
最終ジャッジ日時 | 2024-09-28 12:23:00 |
合計ジャッジ時間 | 15,404 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
51,516 KB |
testcase_01 | AC | 77 ms
51,560 KB |
testcase_02 | AC | 78 ms
51,568 KB |
testcase_03 | AC | 79 ms
51,572 KB |
testcase_04 | AC | 81 ms
51,244 KB |
testcase_05 | AC | 82 ms
51,292 KB |
testcase_06 | AC | 78 ms
51,556 KB |
testcase_07 | AC | 79 ms
51,364 KB |
testcase_08 | AC | 77 ms
51,716 KB |
testcase_09 | AC | 82 ms
51,368 KB |
testcase_10 | AC | 78 ms
51,516 KB |
testcase_11 | AC | 80 ms
51,596 KB |
testcase_12 | AC | 77 ms
51,324 KB |
testcase_13 | AC | 76 ms
51,480 KB |
testcase_14 | AC | 223 ms
56,808 KB |
testcase_15 | AC | 195 ms
56,600 KB |
testcase_16 | AC | 159 ms
54,088 KB |
testcase_17 | AC | 537 ms
66,268 KB |
testcase_18 | AC | 167 ms
53,844 KB |
testcase_19 | AC | 157 ms
53,844 KB |
testcase_20 | AC | 227 ms
57,012 KB |
testcase_21 | AC | 326 ms
60,508 KB |
testcase_22 | AC | 252 ms
59,936 KB |
testcase_23 | AC | 267 ms
60,296 KB |
testcase_24 | AC | 658 ms
80,504 KB |
testcase_25 | AC | 707 ms
80,300 KB |
testcase_26 | AC | 671 ms
80,360 KB |
testcase_27 | AC | 627 ms
80,372 KB |
testcase_28 | AC | 621 ms
80,440 KB |
testcase_29 | AC | 718 ms
80,184 KB |
testcase_30 | AC | 638 ms
80,492 KB |
testcase_31 | AC | 649 ms
80,320 KB |
testcase_32 | AC | 627 ms
80,432 KB |
testcase_33 | AC | 665 ms
80,360 KB |
testcase_34 | AC | 82 ms
51,692 KB |
testcase_35 | AC | 82 ms
51,544 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); List<Point> points = IntStream.range(0, n).mapToObj(i -> new Point(i, sc.nextInt(), sc.nextInt())).toList(); boolean[] broken = new boolean[n]; int[] ans = {0}; points.stream().flatMap(x -> { return points.stream().filter(y -> x.idx < y.idx) .map(y -> new Distance(x, y)); }).sorted() .forEach(z -> { if (z.left == 0) { if (!broken[z.right]) { ans[0]++; broken[z.right] = true; } } else if (!broken[z.left] && !broken[z.right]) { broken[z.left] = true; broken[z.right] = true; } }); System.out.println(ans[0]); } static class Point { int idx; long x; long y; public Point(int idx, long x, long y) { this.idx = idx; this.x = x; this.y = y; } public long getDistance(Point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } } 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 Distance(Point p1, Point p2) { this(p1.idx, p2.idx, p1.getDistance(p2)); } public int compareTo(Distance another) { return Long.compare(value, another.value); } public String toString() { return left + ":" + right + ":" + value; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }