結果

問題 No.1265 Balloon Survival
ユーザー oevloevl
提出日時 2020-10-27 02:37:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 206,124 KB
最終ジャッジ日時 2025-01-15 15:59:40
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using T = tuple<long long, int, int>;

int main() {
    int n; cin >> n;
    vector<P> ps(n);
    for(auto &[x, y] : ps) cin >> x >> y;

    auto distance = [&](auto p, auto p2) -> long long {
        auto[x, y] = p;
        auto[x2, y2] = p2;
        long long dx = x - x2;
        long long dy = y - y2;
        return dx * dx + dy * dy;
    };

    priority_queue<T, vector<T>, greater<T>> que;
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            que.emplace(distance(ps[i], ps[j]), i, j);
        }
    }

    int ans = 0;
    vector<bool> burst(n);
    while(!que.empty()) {
        auto[d, i, j] = que.top();
        que.pop();
        if(burst[i] || burst[j]) continue;
        if(i == 0) {
            burst[j] = true;
            ans++;
        } else {
            burst[i] = true;
            burst[j] = true;
        }
    }
    cout << ans << '\n';
    return 0;
}
0