結果

問題 No.1265 Balloon Survival
ユーザー tentententen
提出日時 2024-02-07 08:34:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 773 ms / 2,000 ms
コード長 2,896 bytes
コンパイル時間 5,402 ms
コンパイル使用メモリ 89,916 KB
実行使用メモリ 84,140 KB
最終ジャッジ日時 2024-02-07 08:34:35
合計ジャッジ時間 18,813 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
55,020 KB
testcase_01 AC 81 ms
54,896 KB
testcase_02 AC 81 ms
54,908 KB
testcase_03 AC 85 ms
55,004 KB
testcase_04 AC 82 ms
54,988 KB
testcase_05 AC 86 ms
55,016 KB
testcase_06 AC 86 ms
55,020 KB
testcase_07 AC 81 ms
54,912 KB
testcase_08 AC 83 ms
54,908 KB
testcase_09 AC 81 ms
54,996 KB
testcase_10 AC 82 ms
54,904 KB
testcase_11 AC 84 ms
55,020 KB
testcase_12 AC 86 ms
55,020 KB
testcase_13 AC 83 ms
54,904 KB
testcase_14 AC 253 ms
60,500 KB
testcase_15 AC 198 ms
60,256 KB
testcase_16 AC 159 ms
57,488 KB
testcase_17 AC 569 ms
69,656 KB
testcase_18 AC 176 ms
57,208 KB
testcase_19 AC 157 ms
57,712 KB
testcase_20 AC 227 ms
60,480 KB
testcase_21 AC 372 ms
63,884 KB
testcase_22 AC 277 ms
63,424 KB
testcase_23 AC 287 ms
63,556 KB
testcase_24 AC 725 ms
84,012 KB
testcase_25 AC 773 ms
84,140 KB
testcase_26 AC 706 ms
83,884 KB
testcase_27 AC 675 ms
83,888 KB
testcase_28 AC 700 ms
81,964 KB
testcase_29 AC 769 ms
84,000 KB
testcase_30 AC 678 ms
83,800 KB
testcase_31 AC 711 ms
83,864 KB
testcase_32 AC 680 ms
83,572 KB
testcase_33 AC 717 ms
83,872 KB
testcase_34 AC 88 ms
55,004 KB
testcase_35 AC 82 ms
55,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
        }
    }
    
}
0