답안 #50144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50144 2018-06-07T18:34:11 Z zetapi 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1660 ms 26368 KB
#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define int long long
#define itr ::iterator 

typedef pair<int,int>  pii;

const int MAX=5e5;

int N,x_,y_,r_,R_cur,R_next,order[MAX],par[MAX];

struct circle
{
	int X;
	int Y;
	int R;
	int ind;
	void init(int X_,int Y_,int R_,int ind_)
	{
		X=X_;
		Y=Y_;
		R=R_;
		ind=ind_;
	}
} 	arr[MAX],lol[MAX];

bool operator<(circle F,circle S)
{
	if(F.X==S.X)
		return F.Y<S.Y;
	return F.X<S.X;
}  

bool cmp(int F,int S)
{
	if(lol[F].R==lol[S].R)
		return lol[F].ind<lol[S].ind;
	return lol[F].R>lol[S].R;
}

bool ok(int F,int S)
{
	return (lol[F].X-lol[S].X)*(lol[F].X-lol[S].X)+(lol[F].Y-lol[S].Y)*(lol[F].Y-lol[S].Y)<=(lol[F].R+lol[S].R)*(lol[F].R+lol[S].R);
}

void init_()
{
	R_cur=R_next;
	R_next/=2;
	for(int A=1;A<=N;A++)
		arr[A].init(lol[A].X/R_cur,lol[A].Y/R_cur,lol[A].R,A);
	sort(arr+1,arr+N+1);
	return ;
}

void solve(int ind)
{
	int tem;
	int pos_x=lol[ind].X/R_cur;
	int pos_y=lol[ind].Y/R_cur;
	par[ind]=ind;
	for(int cur_x=pos_x-2;cur_x<=pos_x+2;cur_x++)
	{
		tem=lower_bound(arr+1,arr+N+1,(circle){cur_x,pos_y-2,0,0})-arr;
		while(tem<=N and arr[tem].X==cur_x and arr[tem].Y<=pos_y+2)
		{
			//cout<<arr[tem].ind<<" "<<ind<<"\n";
			if(par[arr[tem].ind])
			{
				tem++;
				continue;
			}
			else if(ok(ind,arr[tem].ind))
			{
				//cout<<ind<<" "<<arr[tem].ind<<"fu \n";
				par[arr[tem].ind]=ind;
			}
			tem++;
		}
	}
	return ;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	/*cin.tie(0);
	cout.tie(0);*/

	/* 	input
 		11
		9 9 2
		13 2 1
		11 8 2
		3 3 2
		3 12 1
		12 14 1
		9 8 5
		2 8 2
		5 2 1
		14 4 2
		14 14 1
	*/
	cin>>N;
	for(int A=1;A<=N;A++)
	{
		cin>>x_>>y_>>r_;
		order[A]=A;
		lol[A].init(x_,y_,r_,A);
		R_cur=max(R_cur,lol[A].R);
	}
	R_next=R_cur;
	init_();
	sort(order+1,order+N+1,cmp);
	for(int A=1;A<=N;A++)
	{
		if(par[order[A]])
			continue;
		if(lol[order[A]].R<=R_next)
			init_();
		solve(order[A]);
	}
	for(int A=1;A<=N;A++)
		cout<<par[A]<<" ";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 3 ms 520 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 2 ms 608 KB Output is correct
11 Correct 5 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 6 ms 1044 KB Output is correct
20 Correct 5 ms 1100 KB Output is correct
21 Correct 7 ms 1100 KB Output is correct
22 Correct 14 ms 1100 KB Output is correct
23 Correct 15 ms 1100 KB Output is correct
24 Correct 14 ms 1196 KB Output is correct
25 Correct 13 ms 1196 KB Output is correct
26 Correct 14 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 271 ms 26300 KB Output is correct
2 Correct 331 ms 26300 KB Output is correct
3 Correct 309 ms 26300 KB Output is correct
4 Correct 358 ms 26300 KB Output is correct
5 Correct 489 ms 26300 KB Output is correct
6 Correct 643 ms 26300 KB Output is correct
7 Correct 623 ms 26300 KB Output is correct
8 Correct 609 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 26300 KB Output is correct
2 Correct 421 ms 26300 KB Output is correct
3 Correct 1473 ms 26300 KB Output is correct
4 Correct 1357 ms 26300 KB Output is correct
5 Correct 1395 ms 26300 KB Output is correct
6 Correct 377 ms 26300 KB Output is correct
7 Correct 170 ms 26300 KB Output is correct
8 Correct 43 ms 26300 KB Output is correct
9 Correct 1436 ms 26300 KB Output is correct
10 Correct 957 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 662 ms 26300 KB Output is correct
2 Correct 639 ms 26300 KB Output is correct
3 Correct 284 ms 26300 KB Output is correct
4 Correct 486 ms 26300 KB Output is correct
5 Correct 475 ms 26300 KB Output is correct
6 Correct 265 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 3 ms 520 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 2 ms 608 KB Output is correct
11 Correct 5 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 6 ms 1044 KB Output is correct
20 Correct 5 ms 1100 KB Output is correct
21 Correct 7 ms 1100 KB Output is correct
22 Correct 14 ms 1100 KB Output is correct
23 Correct 15 ms 1100 KB Output is correct
24 Correct 14 ms 1196 KB Output is correct
25 Correct 13 ms 1196 KB Output is correct
26 Correct 14 ms 1196 KB Output is correct
27 Correct 17 ms 26300 KB Output is correct
28 Correct 9 ms 26300 KB Output is correct
29 Correct 10 ms 26300 KB Output is correct
30 Correct 30 ms 26300 KB Output is correct
31 Correct 27 ms 26300 KB Output is correct
32 Correct 31 ms 26300 KB Output is correct
33 Correct 102 ms 26300 KB Output is correct
34 Correct 140 ms 26300 KB Output is correct
35 Correct 249 ms 26300 KB Output is correct
36 Correct 386 ms 26300 KB Output is correct
37 Correct 343 ms 26300 KB Output is correct
38 Correct 369 ms 26300 KB Output is correct
39 Correct 576 ms 26300 KB Output is correct
40 Correct 376 ms 26300 KB Output is correct
41 Correct 410 ms 26300 KB Output is correct
42 Correct 101 ms 26300 KB Output is correct
43 Correct 157 ms 26300 KB Output is correct
44 Correct 158 ms 26300 KB Output is correct
45 Correct 153 ms 26300 KB Output is correct
46 Correct 160 ms 26300 KB Output is correct
47 Correct 144 ms 26300 KB Output is correct
48 Correct 192 ms 26300 KB Output is correct
49 Correct 145 ms 26300 KB Output is correct
50 Correct 165 ms 26300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
3 Correct 2 ms 428 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 3 ms 520 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 2 ms 608 KB Output is correct
11 Correct 5 ms 612 KB Output is correct
12 Correct 2 ms 612 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
16 Correct 3 ms 748 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 3 ms 748 KB Output is correct
19 Correct 6 ms 1044 KB Output is correct
20 Correct 5 ms 1100 KB Output is correct
21 Correct 7 ms 1100 KB Output is correct
22 Correct 14 ms 1100 KB Output is correct
23 Correct 15 ms 1100 KB Output is correct
24 Correct 14 ms 1196 KB Output is correct
25 Correct 13 ms 1196 KB Output is correct
26 Correct 14 ms 1196 KB Output is correct
27 Correct 271 ms 26300 KB Output is correct
28 Correct 331 ms 26300 KB Output is correct
29 Correct 309 ms 26300 KB Output is correct
30 Correct 358 ms 26300 KB Output is correct
31 Correct 489 ms 26300 KB Output is correct
32 Correct 643 ms 26300 KB Output is correct
33 Correct 623 ms 26300 KB Output is correct
34 Correct 609 ms 26300 KB Output is correct
35 Correct 3 ms 26300 KB Output is correct
36 Correct 421 ms 26300 KB Output is correct
37 Correct 1473 ms 26300 KB Output is correct
38 Correct 1357 ms 26300 KB Output is correct
39 Correct 1395 ms 26300 KB Output is correct
40 Correct 377 ms 26300 KB Output is correct
41 Correct 170 ms 26300 KB Output is correct
42 Correct 43 ms 26300 KB Output is correct
43 Correct 1436 ms 26300 KB Output is correct
44 Correct 957 ms 26300 KB Output is correct
45 Correct 662 ms 26300 KB Output is correct
46 Correct 639 ms 26300 KB Output is correct
47 Correct 284 ms 26300 KB Output is correct
48 Correct 486 ms 26300 KB Output is correct
49 Correct 475 ms 26300 KB Output is correct
50 Correct 265 ms 26300 KB Output is correct
51 Correct 17 ms 26300 KB Output is correct
52 Correct 9 ms 26300 KB Output is correct
53 Correct 10 ms 26300 KB Output is correct
54 Correct 30 ms 26300 KB Output is correct
55 Correct 27 ms 26300 KB Output is correct
56 Correct 31 ms 26300 KB Output is correct
57 Correct 102 ms 26300 KB Output is correct
58 Correct 140 ms 26300 KB Output is correct
59 Correct 249 ms 26300 KB Output is correct
60 Correct 386 ms 26300 KB Output is correct
61 Correct 343 ms 26300 KB Output is correct
62 Correct 369 ms 26300 KB Output is correct
63 Correct 576 ms 26300 KB Output is correct
64 Correct 376 ms 26300 KB Output is correct
65 Correct 410 ms 26300 KB Output is correct
66 Correct 101 ms 26300 KB Output is correct
67 Correct 157 ms 26300 KB Output is correct
68 Correct 158 ms 26300 KB Output is correct
69 Correct 153 ms 26300 KB Output is correct
70 Correct 160 ms 26300 KB Output is correct
71 Correct 144 ms 26300 KB Output is correct
72 Correct 192 ms 26300 KB Output is correct
73 Correct 145 ms 26300 KB Output is correct
74 Correct 165 ms 26300 KB Output is correct
75 Correct 899 ms 26300 KB Output is correct
76 Correct 352 ms 26368 KB Output is correct
77 Correct 273 ms 26368 KB Output is correct
78 Correct 339 ms 26368 KB Output is correct
79 Correct 1034 ms 26368 KB Output is correct
80 Correct 311 ms 26368 KB Output is correct
81 Correct 1356 ms 26368 KB Output is correct
82 Correct 1240 ms 26368 KB Output is correct
83 Correct 1305 ms 26368 KB Output is correct
84 Correct 1293 ms 26368 KB Output is correct
85 Correct 1301 ms 26368 KB Output is correct
86 Correct 1320 ms 26368 KB Output is correct
87 Correct 1460 ms 26368 KB Output is correct
88 Correct 1346 ms 26368 KB Output is correct
89 Correct 1660 ms 26368 KB Output is correct
90 Correct 1438 ms 26368 KB Output is correct
91 Correct 1396 ms 26368 KB Output is correct
92 Correct 1414 ms 26368 KB Output is correct
93 Correct 797 ms 26368 KB Output is correct
94 Correct 848 ms 26368 KB Output is correct
95 Correct 797 ms 26368 KB Output is correct
96 Correct 955 ms 26368 KB Output is correct
97 Correct 980 ms 26368 KB Output is correct
98 Correct 727 ms 26368 KB Output is correct
99 Correct 897 ms 26368 KB Output is correct
100 Correct 729 ms 26368 KB Output is correct
101 Correct 940 ms 26368 KB Output is correct
102 Correct 827 ms 26368 KB Output is correct
103 Correct 1130 ms 26368 KB Output is correct
104 Correct 806 ms 26368 KB Output is correct
105 Correct 404 ms 26368 KB Output is correct
106 Correct 496 ms 26368 KB Output is correct
107 Correct 505 ms 26368 KB Output is correct
108 Correct 497 ms 26368 KB Output is correct
109 Correct 549 ms 26368 KB Output is correct
110 Correct 507 ms 26368 KB Output is correct
111 Correct 480 ms 26368 KB Output is correct
112 Correct 514 ms 26368 KB Output is correct
113 Correct 491 ms 26368 KB Output is correct
114 Correct 501 ms 26368 KB Output is correct
115 Correct 466 ms 26368 KB Output is correct
116 Correct 462 ms 26368 KB Output is correct