제출 #260879

#제출 시각아이디문제언어결과실행 시간메모리
260879wiwiho원 고르기 (APIO18_circle_selection)C++14
7 / 100
3077 ms1048580 KiB
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

const ll MAX = 2147483647;

ll dis(pll a, pll b){
    ll x = a.F - b.F;
    ll y = a.S - b.S;
    return x * x + y *y ;
}

struct Comp{

    bool operator()(pll a, pll b){
        if(a.F == b.F) return a.S < b.S;
        return a.F > b.F;
    }

};

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

    int n;
    cin >> n;

    vector<pair<ll, pll>> c(n);

    for(int i = 0; i < n; i++){
        cin >> c[i].S.F >> c[i].S.S >> c[i].F;
    }
    
    vector<int> a(n);

    vector<vector<int>> is(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(dis(c[i].S, c[j].S) <= (c[i].F + c[j].F) * (c[i].F + c[j].F))
                is[i].eb(j);
        }
    }

    set<pll, Comp> pq;
    for(int i = 0; i < n; i++) pq.insert(mp(c[i].F, i));

    while(!pq.empty()){
        int now = pq.begin()->S;
        pq.erase(pq.begin());
        a[now] = now;
        for(int i : is[now]){
            if(pq.find(mp(c[i].F, i)) != pq.end()){
                a[i] = now;
                pq.erase(mp(c[i].F, i));
            }
        }
    }

    for(int i = 0; i < n; i++) cout << a[i] + 1 << " ";
    cout << "\n";

    return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...