結果

問題 No.1265 Balloon Survival
ユーザー finefine
提出日時 2020-10-23 22:12:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 176,124 KB
実行使用メモリ 12,572 KB
最終ジャッジ日時 2023-09-28 16:00:56
合計ジャッジ時間 4,194 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 52 ms
11,828 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 8 ms
4,376 KB
testcase_21 AC 25 ms
5,160 KB
testcase_22 AC 12 ms
5,144 KB
testcase_23 AC 16 ms
5,160 KB
testcase_24 AC 109 ms
12,572 KB
testcase_25 AC 113 ms
11,628 KB
testcase_26 AC 111 ms
12,260 KB
testcase_27 AC 81 ms
11,796 KB
testcase_28 AC 81 ms
11,744 KB
testcase_29 AC 103 ms
12,520 KB
testcase_30 AC 86 ms
11,968 KB
testcase_31 AC 106 ms
12,524 KB
testcase_32 AC 70 ms
11,844 KB
testcase_33 AC 83 ms
12,008 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using T = tuple<ll, int, int>;

constexpr char newl = '\n';

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<ll> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }

    priority_queue<T, vector<T>, greater<T> > pq;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            ll dx = x[i] - x[j], dy = y[i] - y[j];
            pq.emplace(dx * dx + dy * dy, j, i);
        }
    }

    vector<int> used(n, false);
    int ans = 0;
    int rest = n - 1;
    while (!pq.empty() && rest) {
        ll dist;
        int i, j;
        tie(dist, i, j) = pq.top();
        pq.pop();

        if (i == 0) {
            if (used[j]) continue;
            ++ans;
            used[j] = true;
            --rest;
        } else {
            if (used[i] || used[j]) continue;
            used[i] = true;
            used[j] = true;
            rest -= 2;
        }
    }
    cout << ans << newl;

    return 0;
}
0