Submission #403793

#TimeUsernameProblemLanguageResultExecution timeMemory
403793rqiCircle selection (APIO18_circle_selection)C++14
7 / 100
3079 ms25544 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<int> vi;

#define f first
#define s second
#define pb push_back
#define all(x) begin(x), end(x)
#define mp make_pair


#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct hashFunc{
	size_t operator()(const pl& a)const {
		return a.f ^(a.s+1);
	}
};

const int mx = 300005;
int n;
ll x[mx];
ll y[mx];
ll r[mx];
bool present[mx];
int ans[mx];

bool circleIntersect(int a, int b){
	ll dist = (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
	if(dist <= (r[a]+r[b])*(r[a]+r[b])) return 1;
	return 0;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	//gp_hash_table<pl, vi, hashFunc> g;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> x[i] >> y[i] >> r[i];
	}
	vector<pair<ll, int>> v;
	for(int i = 1; i <= n; i++){
		v.pb(mp(-r[i], i));
	}
	sort(all(v));
	vi inds;
	for(int i = 0; i < n; i++){
		inds.pb(v[i].s);
	}
	for(int i = 1; i <= n; i++){
		present[i] = 1;
	}
	for(auto ind: inds){
		if(present[ind]){
			present[ind] = 0;
			ans[ind] = ind;
			for(int i = 1; i <= n; i++){
				if(present[i] && circleIntersect(i, ind)){
					present[i] = 0;
					ans[i] = ind;
				}
			}
		}
		
	}
	for(int i = 1; i <= n; i++){
		cout << ans[i] << " ";
	}
	cout << "\n";
}
#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...