제출 #1359292

#제출 시각아이디문제언어결과실행 시간메모리
1359292Faisal_Saqib원 고르기 (APIO18_circle_selection)C++17
0 / 100
3095 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+100;
const int SQ=1e4;//  333 444
vector<int> adj[N];
ll who[N];
void solve()
{
	ll n;
	cin>>n;
	vector<ll> x(n),y(n),r(n);
	set<ll> tpy;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>r[i];
		tpy.insert(y[i]);
	}
		vector<pair<pair<ll,ll>,ll>> tp(n);
		for(int i=0;i<n;i++)
		{
			tp[i].first={x[i],y[i]};
			tp[i].second=i;
		}
		sort(begin(tp),end(tp));
		for(int jp=0;jp<n;jp++)
		{
			for(int l=1;l<=SQ;l++)
			{
				if((jp+l)>=0 and (jp+l)<n)
				{
					int i=tp[jp].second;
					int j=tp[jp+l].second;
					ll dist=(r[i]+r[j])*(r[i]+r[j]);
					ll dp=( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
					if(dp<=dist)
					{
						adj[i].push_back(j);
						adj[j].push_back(i);
					}
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			tp[i].first={y[i],x[i]};
			tp[i].second=i;
		}
		sort(begin(tp),end(tp));
		for(int jp=0;jp<n;jp++)
		{
			for(int l=1;l<=SQ;l++)
			{
				if((jp+l)>=0 and (jp+l)<n)
				{
					int i=tp[jp].second;
					int j=tp[jp+l].second;
					ll dist=(r[i]+r[j])*(r[i]+r[j]);
					ll dp=( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
					if(dp<=dist)
					{
						adj[i].push_back(j);
						adj[j].push_back(i);
					}
				}
			}
		}
		set<pair<int,int>> rem;
		for(int i=0;i<n;i++)
			rem.insert({-r[i],i});
		while(rem.size())
		{
			auto p=*begin(rem);
			rem.erase(begin(rem));
			if(who[p.second]!=0)
				continue;
			for(auto op:adj[p.second])
				if(who[op]==0)
					who[op]=p.second+1;
		}
		for(int i=0;i<n;i++)
		{
			cout<<who[i]<<' ';
		}
		cout<<'\n';
}
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	solve();
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…