結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct P {
    int x, y;
};

struct Q {
    bool operator<(const Q &q) const {
        return d < q.d;
    }
    ll d;
    int i, j;
};

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

    int n;
    cin >> n;

    vector<P> p(n);
    vector<Q> q(n * (n - 1) / 2);
    int h = 0;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;

        p[i] = { x, y };

        for (int j = 0; j < i; j++) {
            ll dx = x - p[j].x;
            ll dy = y - p[j].y;
            q[h++] = { dx * dx + dy * dy, i, j };
        }
    }

    sort(q.begin(), q.end());

    vector<int> b(n, 1);
    int r = 0;

    for (auto [d, i, j] : q) {
        if (b[i] && b[j]) {
            if (j == 0) {
                b[i] = 0;
                r++;
            } else {
                b[i] = b[j] = 0;
            }
        }
    }

    cout << r << endl;

    return 0;
}
0