結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int64_t> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i) >> y.at(i);
    }
    vector d(n, vector(n, 0L));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int64_t dx = x.at(i) - x.at(j), dy = y.at(i) - y.at(j);
            d.at(i).at(j) = dx * dx + dy * dy;
        }
    }
    vector<tuple<int64_t, int, int>> p;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            p.emplace_back(d.at(i).at(j), i, j);
        }
    }
    sort(p.begin(), p.end());
    int ans = 0;
    vector<bool> disappeared(n);
    for (auto x : p) {
        auto [_, a, b] = x;
        if (disappeared.at(a) or disappeared.at(b)) continue;
        if (a == 0) {
            disappeared.at(b) = true;
            ans++;
        } else {
            disappeared.at(a) = true;
            disappeared.at(b) = true;
        }
    }
    cout << ans << endl;
}
0