結果
問題 | No.1265 Balloon Survival |
ユーザー |
![]() |
提出日時 | 2024-02-07 08:34:09 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
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();}}}