답안 #1043500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1043500 2024-08-04T10:12:43 Z vjudge1 원 고르기 (APIO18_circle_selection) C++17
34 / 100
1182 ms 82240 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

bool inte(vector<int> c,vector<int> c1)
{
	int dis=(c[2]-c1[2])*(c[2]-c1[2])+(c[3]-c1[3])*(c[3]-c1[3]);
	return dis <= (c[0]+c1[0])*(c[0]+c1[0]);
}

signed main()
{
	int n;
	cin>>n;
	int r[n],x[n],y[n],ans[n]={};
	for (int i=0;i<n;i++)
		cin>>x[i]>>y[i]>>r[i];
	if (n<=5000)
	{
		set<vector<int>> se;
		set<int> rem;
		for (int i=0;i<n;i++)
		{
			se.insert({-r[i],i,x[i],y[i]});
			rem.insert(i);
		}
		while (!se.empty())
		{
			auto it=se.begin();
			vector<int> c=*it;c[0]*=-1;
			for (int i:rem)
				if (!ans[i] && inte(c,{r[i],i,x[i],y[i]}))
				{
					se.erase({-r[i],i,x[i],y[i]});
					ans[i]=c[1]+1;
				}
		}
	}
	else
	{
		int mx=-1e9,mn=-mx;
		for (int i=0;i<n;i++)
			mn=min(mn,y[i]),mx=max(mx,y[i]);
		if (!mn && !mx)
		{
			set<pair<int,int>> st,en,rem;
			for (int i=0;i<n;i++)
				st.insert({x[i]-r[i],i}),en.insert({x[i]+r[i],i}),rem.insert({-r[i],i});
			while (!rem.empty())
			{
				set<int> toer;
				auto p=*rem.begin();
				auto it=st.lower_bound({x[p.second]-r[p.second],0});
				auto it1=st.lower_bound({1+x[p.second]+r[p.second],0});
				while (it!=it1)
				{
					toer.insert((*it).second);
					it++;
				}
				it=en.lower_bound({x[p.second]-r[p.second],0});
				it1=en.lower_bound({x[p.second]+r[p.second]+1,0});
				while (it!=it1)
				{
					toer.insert((*it).second);
					it++;
				}
				for (int i:toer)
				{
					ans[i]=p.second+1;
					st.erase({x[i]-r[i],i}),en.erase({x[i]+r[i],i}),rem.erase({-r[i],i});
				}
			}
		}
		else
		{
			vector<vector<int>> vec;
			for (int i=0;i<n;i++)
				vec.push_back({y[i]+r[i],i,1}),vec.push_back({y[i]-r[i],i,0});
			sort(vec.begin(),vec.end());
			set<pair<int,int>> ms;
			while (!vec.empty())
			{
				vector<int> v=vec.back();
				vec.pop_back();
				if (v[2])
				{
					auto it=ms.insert({x[v[1]],v[1]}).first;
					if (it!=ms.begin())
					{
						it--;
						int id=(*it).second;
						if (inte({r[v[1]],0,x[v[1]],y[v[1]]},{r[id],0,x[id],y[id]}))
						{
							if (r[v[1]]>r[id] || (r[v[1]]==r[id] && v[1]<id))
								ans[v[1]]=ans[id]=v[1]+1;
							else
								ans[v[1]]=ans[id]=id+1;
						}
						it++;
					}
					it++;
					if (it!=ms.end())
					{
						int id=(*it).second;
						if (inte({r[v[1]],0,x[v[1]],y[v[1]]},{r[id],0,x[id],y[id]}))
						{
							if (r[v[1]]>r[id] || (r[v[1]]==r[id] && v[1]<id))
								ans[v[1]]=ans[id]=v[1]+1;
							else
								ans[v[1]]=ans[id]=id+1;
						}
					}
				}
				else
				{
					auto it=ms.find({x[v[1]],v[1]});
					if (it!=ms.begin())
					{
						it--;
						int id=(*it).second;
						it++,it++;
						if (it!=ms.end())
						{
							int id1=(*it).second;
							if (inte({r[id],0,x[id],y[id]},{r[id1],0,x[id1],y[id1]}))
							{
								if (r[id]>r[id1] || (r[id]==r[id1] && id<id1))
									ans[id]=ans[id1]=id+1;
								else
									ans[id]=ans[id1]=id1+1;
							}
						}
					}
					ms.erase({x[v[1]],v[1]});
				}
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		if (!ans[i])
			ans[i]=i+1;
		cout<<ans[i]<<' ';
	}
	cout<<endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 432 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 6 ms 1372 KB Output is correct
20 Correct 6 ms 1360 KB Output is correct
21 Correct 6 ms 1372 KB Output is correct
22 Correct 428 ms 1348 KB Output is correct
23 Correct 441 ms 1360 KB Output is correct
24 Correct 419 ms 1368 KB Output is correct
25 Correct 440 ms 1360 KB Output is correct
26 Correct 412 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1167 ms 81992 KB Output is correct
2 Correct 1084 ms 75332 KB Output is correct
3 Correct 1102 ms 79924 KB Output is correct
4 Correct 1182 ms 82240 KB Output is correct
5 Correct 782 ms 68180 KB Output is correct
6 Correct 782 ms 67928 KB Output is correct
7 Correct 807 ms 68116 KB Output is correct
8 Correct 787 ms 67948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 119 ms 14988 KB Output is correct
3 Correct 407 ms 59464 KB Output is correct
4 Correct 444 ms 59132 KB Output is correct
5 Correct 451 ms 60528 KB Output is correct
6 Correct 210 ms 30552 KB Output is correct
7 Correct 98 ms 15876 KB Output is correct
8 Correct 22 ms 3912 KB Output is correct
9 Correct 416 ms 59888 KB Output is correct
10 Correct 442 ms 60408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 388 ms 51448 KB Output is correct
2 Correct 322 ms 59392 KB Output is correct
3 Incorrect 505 ms 60412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 432 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 6 ms 1372 KB Output is correct
20 Correct 6 ms 1360 KB Output is correct
21 Correct 6 ms 1372 KB Output is correct
22 Correct 428 ms 1348 KB Output is correct
23 Correct 441 ms 1360 KB Output is correct
24 Correct 419 ms 1368 KB Output is correct
25 Correct 440 ms 1360 KB Output is correct
26 Correct 412 ms 1356 KB Output is correct
27 Incorrect 15 ms 2064 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 432 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 6 ms 1372 KB Output is correct
20 Correct 6 ms 1360 KB Output is correct
21 Correct 6 ms 1372 KB Output is correct
22 Correct 428 ms 1348 KB Output is correct
23 Correct 441 ms 1360 KB Output is correct
24 Correct 419 ms 1368 KB Output is correct
25 Correct 440 ms 1360 KB Output is correct
26 Correct 412 ms 1356 KB Output is correct
27 Correct 1167 ms 81992 KB Output is correct
28 Correct 1084 ms 75332 KB Output is correct
29 Correct 1102 ms 79924 KB Output is correct
30 Correct 1182 ms 82240 KB Output is correct
31 Correct 782 ms 68180 KB Output is correct
32 Correct 782 ms 67928 KB Output is correct
33 Correct 807 ms 68116 KB Output is correct
34 Correct 787 ms 67948 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 119 ms 14988 KB Output is correct
37 Correct 407 ms 59464 KB Output is correct
38 Correct 444 ms 59132 KB Output is correct
39 Correct 451 ms 60528 KB Output is correct
40 Correct 210 ms 30552 KB Output is correct
41 Correct 98 ms 15876 KB Output is correct
42 Correct 22 ms 3912 KB Output is correct
43 Correct 416 ms 59888 KB Output is correct
44 Correct 442 ms 60408 KB Output is correct
45 Correct 388 ms 51448 KB Output is correct
46 Correct 322 ms 59392 KB Output is correct
47 Incorrect 505 ms 60412 KB Output isn't correct
48 Halted 0 ms 0 KB -