結果

問題 No.1265 Balloon Survival
ユーザー sten_sansten_san
提出日時 2020-10-29 20:41:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 210,488 KB
実行使用メモリ 16,324 KB
最終ジャッジ日時 2023-09-29 04:05:07
合計ジャッジ時間 5,401 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 15 ms
4,672 KB
testcase_15 AC 12 ms
4,796 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 75 ms
15,744 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 6 ms
4,376 KB
testcase_20 AC 16 ms
4,740 KB
testcase_21 AC 34 ms
6,244 KB
testcase_22 AC 22 ms
6,516 KB
testcase_23 AC 23 ms
6,456 KB
testcase_24 AC 161 ms
15,960 KB
testcase_25 AC 162 ms
15,984 KB
testcase_26 AC 152 ms
15,532 KB
testcase_27 AC 156 ms
16,020 KB
testcase_28 AC 152 ms
15,988 KB
testcase_29 AC 156 ms
15,952 KB
testcase_30 AC 154 ms
16,072 KB
testcase_31 AC 151 ms
15,992 KB
testcase_32 AC 153 ms
16,324 KB
testcase_33 AC 152 ms
15,536 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

int main() {
    int n; cin >> n;
    vec<array<int, 2>> bal(n);
    for (auto &[x, y]: bal) cin >> x >> y;

    using dist_t = array<int64_t, 3>;
    priority_queue<dist_t, vector<dist_t>, greater<dist_t>> que;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int64_t dx = abs(bal[i][0] - bal[j][0]), dy = abs(bal[i][1] - bal[j][1]);
            que.push({ dx * dx + dy * dy , i, j });
        }
    }

    int ans = 0;

    vec<bool> used(n, false);
    while (que.size()) {
        auto [d, a, b] = que.top(); que.pop();
        if (used[a] || used[b]) continue;

        tie(a, b) = make_tuple(min(a, b), max(a, b));
        used[a] = a != 0;
        used[b] = true;

        ans += a == 0;
    }

    cout << ans << endl;
}

0