結果

問題 No.1265 Balloon Survival
ユーザー tentententen
提出日時 2022-08-04 16:52:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 2,644 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 75,556 KB
実行使用メモリ 81,516 KB
最終ジャッジ日時 2023-10-12 14:39:54
合計ジャッジ時間 11,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,400 KB
testcase_01 AC 43 ms
49,496 KB
testcase_02 AC 43 ms
49,524 KB
testcase_03 AC 44 ms
49,520 KB
testcase_04 AC 44 ms
49,612 KB
testcase_05 AC 46 ms
49,592 KB
testcase_06 AC 45 ms
49,496 KB
testcase_07 AC 44 ms
49,464 KB
testcase_08 AC 45 ms
49,376 KB
testcase_09 AC 43 ms
49,492 KB
testcase_10 AC 43 ms
49,488 KB
testcase_11 AC 44 ms
49,400 KB
testcase_12 AC 45 ms
49,416 KB
testcase_13 AC 43 ms
49,816 KB
testcase_14 AC 157 ms
55,168 KB
testcase_15 AC 146 ms
54,824 KB
testcase_16 AC 99 ms
52,248 KB
testcase_17 AC 341 ms
66,888 KB
testcase_18 AC 114 ms
52,356 KB
testcase_19 AC 101 ms
50,740 KB
testcase_20 AC 163 ms
55,032 KB
testcase_21 AC 210 ms
58,408 KB
testcase_22 AC 175 ms
57,908 KB
testcase_23 AC 184 ms
58,252 KB
testcase_24 AC 519 ms
81,416 KB
testcase_25 AC 527 ms
81,092 KB
testcase_26 AC 493 ms
80,948 KB
testcase_27 AC 511 ms
81,212 KB
testcase_28 AC 527 ms
81,112 KB
testcase_29 AC 523 ms
81,100 KB
testcase_30 AC 519 ms
81,076 KB
testcase_31 AC 527 ms
81,148 KB
testcase_32 AC 532 ms
81,224 KB
testcase_33 AC 529 ms
81,516 KB
testcase_34 AC 46 ms
49,400 KB
testcase_35 AC 43 ms
49,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        PriorityQueue<Path> queue = new PriorityQueue<>();
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                queue.add(new Path(i, j, points[i].getDistance(points[j])));
            }
        }
        HashSet<Integer> removed = new HashSet<>();
        int count = 0;
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (removed.contains(p.left) || removed.contains(p.right)) {
                continue;
            }
            if (p.left == 0) {
                removed.add(p.right);
                count++;
                continue;
            }
            removed.add(p.left);
            removed.add(p.right);
        }
        System.out.println(count);
    }
    
    static class Path implements Comparable<Path> {
        int left;
        int right;
        long value;
        
        public Path(int left, int right, long value) {
            this.left = left;
            this.right = right;
            this.value = value;
        }
        
        public int compareTo(Path 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 Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0