結果

問題 No.1265 Balloon Survival
ユーザー rogi52
提出日時 2022-10-04 19:43:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 205,332 KB
最終ジャッジ日時 2025-02-07 21:21:55
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N; cin >> N;
    vector<ll> x(N), y(N);
    rep(i,N) cin >> x[i] >> y[i];

    vector<pair<ll,pair<int,int>>> e;
    rep(i,N)rep(j,i) {
        ll t = 0;
        t += (x[i] - x[j]) * (x[i] - x[j]);
        t += (y[i] - y[j]) * (y[i] - y[j]);
        e.push_back({t, {i, j}});
    }

    sort(e.begin(), e.end());
    vector<int> alive(N, 1);
    int ans = 0;
    for(auto [t, PAIR] : e) {
        auto [i, j] = PAIR;
        if(alive[i] && alive[j]) {
            if(j == 0) ans++;
            else alive[j] = 0;
            alive[i] = 0;
        }
    }

    cout << ans << endl;
}
0