結果

問題 No.1265 Balloon Survival
ユーザー nebukuro09nebukuro09
提出日時 2020-10-23 22:19:27
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 135,392 KB
実行使用メモリ 12,444 KB
最終ジャッジ日時 2023-09-04 10:50:19
合計ジャッジ時間 5,747 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 29 ms
4,384 KB
testcase_15 AC 21 ms
4,384 KB
testcase_16 AC 8 ms
4,384 KB
testcase_17 AC 135 ms
7,100 KB
testcase_18 AC 12 ms
4,380 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 27 ms
4,384 KB
testcase_21 AC 62 ms
5,028 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 41 ms
4,380 KB
testcase_24 AC 278 ms
10,904 KB
testcase_25 AC 276 ms
10,980 KB
testcase_26 AC 275 ms
10,852 KB
testcase_27 AC 281 ms
10,900 KB
testcase_28 AC 275 ms
10,860 KB
testcase_29 AC 278 ms
10,856 KB
testcase_30 AC 273 ms
10,856 KB
testcase_31 AC 279 ms
10,936 KB
testcase_32 AC 276 ms
12,444 KB
testcase_33 AC 274 ms
10,872 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime;


void main() {
    auto N = readln.chomp.to!int;
    auto A = iota(N).map!(_ => readln.split.map!(to!long).array).array;

    long dist(int i, int j) {
        return (A[i][0] - A[j][0]) ^^ 2 + (A[i][1] - A[j][1]) ^^ 2;
    }

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    foreach (i; 0..N) foreach (j; i+1..N) pq.insert(tuple(i, j, dist(i, j)));

    auto used = new bool[](N);
    int ans = 0;

    while (!pq.empty) {
        auto i = pq.front[0];
        auto j = pq.front[1];
        pq.removeFront;
        if (used[i] || used[j]) {
            continue;
        } if (i == 0) {
            ans += 1;
            used[j] = true;
        } else {
            used[i] = used[j] = true;
        }
    }

    ans.writeln;
}
0