답안 #356821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
356821 2021-01-23T18:37:35 Z CaroLinda 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1280 ms 43284 KB
/*
Proof of complexity: https://en.wikipedia.org/wiki/Circle_packing_in_a_square
*/
#include <bits/stdc++.h>

#define debug printf
#define ll long long
#define sz(x) (int)(x.size() )
#define all(x) x.begin(),x.end()
 
const int MAXN = 3e5+10 ;
 
using namespace std ;
 
struct Circle
{
	ll x , y , r ;
 
	Circle(ll x = 0 , ll y = 0 , ll r = 0 ) : x(x), y(y) , r(r) {}
 
} c[MAXN] ;
 
int N , idx ;
int ans[MAXN] , myBlock[MAXN] ;
ll meaning[MAXN] ;
ll G ;
vector<int> byY , byX ;
vector< pair<ll,int> > v[MAXN] ;
 
bool test(int i, int j )
{
	ll dx = c[i].x - c[j].x ;
	ll dy = c[i].y - c[j].y ;
	ll dr = c[i].r + c[j].r ;
	return dx*dx + dy*dy <= dr * dr ;
}
 
void rescale()
{
	for(int i = 0 ; i <= idx ; i++ ) v[i].clear() ;
	
	idx = -1 ;

	for(int e : byX )
	{
		if(ans[e] != -1 ) continue ;
		
		if(idx == -1  || (c[e].x/G) > meaning[idx] )
		{
			myBlock[e] = ++idx ;
			meaning[idx] = (c[e].x/G) ;
		}
		else myBlock[e] = idx ;		
	}	

	for(int e : byY )
	{
		if(ans[e] != -1 ) continue ;
		v[ myBlock[e] ].push_back(make_pair(c[e].y, e) ) ;
	}

	/*debug("Printing rescale with radio %d\n", G) ;
	for(int i= 0 ; i <= idx ; i++ )
	{
		debug("In the x %d: ", meaning[i] ) ;
		for(auto e : v[i] ) debug("%lld %d, ", e.first, e.second ) ;
		debug("\n") ;
	}*/ 

}

int main()
{

	scanf("%d", &N ) ;
	for(int i = 0 ; i < N ; i++ ) 
	{
		scanf("%lld %lld %lld", &c[i].x, &c[i].y, &c[i].r) ;
		ans[i] = -1 ;
	}

	vector<int> byRadio(N) ; iota(all(byRadio), 0 );
	sort(all(byRadio), [&](int i, int j) 
	{
		if( c[i].r != c[j].r ) return c[i].r > c[j].r ;
		return i< j ;
	} ) ;

	byY.resize(N) ; iota(all(byY),0) ;
	sort(all(byY), [&](int i, int j ) { return c[i].y < c[j].y ; } ) ;

	byX.resize(N) ; iota(all(byX), 0) ;
	sort(all(byX), [&](int i, int j ) { return c[i].x < c[j].x ; } ) ;

	G = c[ byRadio[0] ].r * 2LL + 1 ;

	for(auto e : byRadio )
	{
		if( ans[e] != -1 ) continue ;

		if( c[e].r*2LL < G )
		{
			G = c[e].r ;
			rescale() ;
		}		

		int l = max(0,myBlock[e]-2) ;
		int r = min(myBlock[e]+2, idx ) ;

		ll lo = c[e].y-2LL*c[e].r ;
		ll hi = c[e].y+2LL*c[e].r ;

		for(int i = l ; i <= r ; i++ )
		{
			int t = lower_bound(all(v[i]), make_pair(lo, -1 ) ) - v[i].begin() ;
			for(; t < sz(v[i]) && v[i][t].first <= hi ; t++ )
			{
				if( ans[ v[i][t].second ] != -1 ) continue ;
				if( test(v[i][t].second, e ) ) ans[ v[i][t].second ] = e ;
			}
		}

	}
	
	for(int i = 0 ; i < N ; i++ ) printf("%d ", ans[i]+1 ) ;
	printf("\n") ;	 
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |  scanf("%d", &N ) ;
      |  ~~~~~^~~~~~~~~~~
circle_selection.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   78 |   scanf("%lld %lld %lld", &c[i].x, &c[i].y, &c[i].r) ;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14444 KB Output is correct
2 Correct 8 ms 14444 KB Output is correct
3 Correct 10 ms 14444 KB Output is correct
4 Correct 10 ms 14444 KB Output is correct
5 Correct 10 ms 14444 KB Output is correct
6 Correct 9 ms 14444 KB Output is correct
7 Correct 10 ms 14444 KB Output is correct
8 Correct 8 ms 14444 KB Output is correct
9 Correct 9 ms 14444 KB Output is correct
10 Correct 9 ms 14444 KB Output is correct
11 Correct 8 ms 14444 KB Output is correct
12 Correct 8 ms 14444 KB Output is correct
13 Correct 9 ms 14444 KB Output is correct
14 Correct 8 ms 14452 KB Output is correct
15 Correct 8 ms 14468 KB Output is correct
16 Correct 9 ms 14444 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14444 KB Output is correct
19 Correct 13 ms 14700 KB Output is correct
20 Correct 13 ms 14700 KB Output is correct
21 Correct 15 ms 14700 KB Output is correct
22 Correct 15 ms 14700 KB Output is correct
23 Correct 14 ms 14700 KB Output is correct
24 Correct 13 ms 14700 KB Output is correct
25 Correct 13 ms 14700 KB Output is correct
26 Correct 15 ms 14700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 319 ms 28632 KB Output is correct
2 Correct 288 ms 29652 KB Output is correct
3 Correct 318 ms 27064 KB Output is correct
4 Correct 282 ms 28756 KB Output is correct
5 Correct 284 ms 29616 KB Output is correct
6 Correct 391 ms 31468 KB Output is correct
7 Correct 313 ms 30444 KB Output is correct
8 Correct 326 ms 30444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14444 KB Output is correct
2 Correct 150 ms 20204 KB Output is correct
3 Correct 583 ms 31824 KB Output is correct
4 Correct 562 ms 31980 KB Output is correct
5 Correct 536 ms 33228 KB Output is correct
6 Correct 221 ms 23460 KB Output is correct
7 Correct 107 ms 19052 KB Output is correct
8 Correct 26 ms 15340 KB Output is correct
9 Correct 571 ms 35004 KB Output is correct
10 Correct 512 ms 35260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 464 ms 30720 KB Output is correct
2 Correct 445 ms 34028 KB Output is correct
3 Correct 334 ms 28524 KB Output is correct
4 Correct 456 ms 33488 KB Output is correct
5 Correct 439 ms 33772 KB Output is correct
6 Correct 303 ms 27372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14444 KB Output is correct
2 Correct 8 ms 14444 KB Output is correct
3 Correct 10 ms 14444 KB Output is correct
4 Correct 10 ms 14444 KB Output is correct
5 Correct 10 ms 14444 KB Output is correct
6 Correct 9 ms 14444 KB Output is correct
7 Correct 10 ms 14444 KB Output is correct
8 Correct 8 ms 14444 KB Output is correct
9 Correct 9 ms 14444 KB Output is correct
10 Correct 9 ms 14444 KB Output is correct
11 Correct 8 ms 14444 KB Output is correct
12 Correct 8 ms 14444 KB Output is correct
13 Correct 9 ms 14444 KB Output is correct
14 Correct 8 ms 14452 KB Output is correct
15 Correct 8 ms 14468 KB Output is correct
16 Correct 9 ms 14444 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14444 KB Output is correct
19 Correct 13 ms 14700 KB Output is correct
20 Correct 13 ms 14700 KB Output is correct
21 Correct 15 ms 14700 KB Output is correct
22 Correct 15 ms 14700 KB Output is correct
23 Correct 14 ms 14700 KB Output is correct
24 Correct 13 ms 14700 KB Output is correct
25 Correct 13 ms 14700 KB Output is correct
26 Correct 15 ms 14700 KB Output is correct
27 Correct 17 ms 14972 KB Output is correct
28 Correct 17 ms 15024 KB Output is correct
29 Correct 17 ms 14956 KB Output is correct
30 Correct 21 ms 14956 KB Output is correct
31 Correct 20 ms 14956 KB Output is correct
32 Correct 20 ms 14956 KB Output is correct
33 Correct 99 ms 18704 KB Output is correct
34 Correct 101 ms 19168 KB Output is correct
35 Correct 106 ms 18772 KB Output is correct
36 Correct 147 ms 19948 KB Output is correct
37 Correct 147 ms 20000 KB Output is correct
38 Correct 148 ms 20000 KB Output is correct
39 Correct 205 ms 22620 KB Output is correct
40 Correct 206 ms 22620 KB Output is correct
41 Correct 249 ms 22748 KB Output is correct
42 Correct 88 ms 19820 KB Output is correct
43 Correct 134 ms 20772 KB Output is correct
44 Correct 109 ms 20884 KB Output is correct
45 Correct 110 ms 20844 KB Output is correct
46 Correct 134 ms 20844 KB Output is correct
47 Correct 106 ms 20864 KB Output is correct
48 Correct 112 ms 20972 KB Output is correct
49 Correct 117 ms 20844 KB Output is correct
50 Correct 108 ms 20844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14444 KB Output is correct
2 Correct 8 ms 14444 KB Output is correct
3 Correct 10 ms 14444 KB Output is correct
4 Correct 10 ms 14444 KB Output is correct
5 Correct 10 ms 14444 KB Output is correct
6 Correct 9 ms 14444 KB Output is correct
7 Correct 10 ms 14444 KB Output is correct
8 Correct 8 ms 14444 KB Output is correct
9 Correct 9 ms 14444 KB Output is correct
10 Correct 9 ms 14444 KB Output is correct
11 Correct 8 ms 14444 KB Output is correct
12 Correct 8 ms 14444 KB Output is correct
13 Correct 9 ms 14444 KB Output is correct
14 Correct 8 ms 14452 KB Output is correct
15 Correct 8 ms 14468 KB Output is correct
16 Correct 9 ms 14444 KB Output is correct
17 Correct 9 ms 14444 KB Output is correct
18 Correct 9 ms 14444 KB Output is correct
19 Correct 13 ms 14700 KB Output is correct
20 Correct 13 ms 14700 KB Output is correct
21 Correct 15 ms 14700 KB Output is correct
22 Correct 15 ms 14700 KB Output is correct
23 Correct 14 ms 14700 KB Output is correct
24 Correct 13 ms 14700 KB Output is correct
25 Correct 13 ms 14700 KB Output is correct
26 Correct 15 ms 14700 KB Output is correct
27 Correct 319 ms 28632 KB Output is correct
28 Correct 288 ms 29652 KB Output is correct
29 Correct 318 ms 27064 KB Output is correct
30 Correct 282 ms 28756 KB Output is correct
31 Correct 284 ms 29616 KB Output is correct
32 Correct 391 ms 31468 KB Output is correct
33 Correct 313 ms 30444 KB Output is correct
34 Correct 326 ms 30444 KB Output is correct
35 Correct 9 ms 14444 KB Output is correct
36 Correct 150 ms 20204 KB Output is correct
37 Correct 583 ms 31824 KB Output is correct
38 Correct 562 ms 31980 KB Output is correct
39 Correct 536 ms 33228 KB Output is correct
40 Correct 221 ms 23460 KB Output is correct
41 Correct 107 ms 19052 KB Output is correct
42 Correct 26 ms 15340 KB Output is correct
43 Correct 571 ms 35004 KB Output is correct
44 Correct 512 ms 35260 KB Output is correct
45 Correct 464 ms 30720 KB Output is correct
46 Correct 445 ms 34028 KB Output is correct
47 Correct 334 ms 28524 KB Output is correct
48 Correct 456 ms 33488 KB Output is correct
49 Correct 439 ms 33772 KB Output is correct
50 Correct 303 ms 27372 KB Output is correct
51 Correct 17 ms 14972 KB Output is correct
52 Correct 17 ms 15024 KB Output is correct
53 Correct 17 ms 14956 KB Output is correct
54 Correct 21 ms 14956 KB Output is correct
55 Correct 20 ms 14956 KB Output is correct
56 Correct 20 ms 14956 KB Output is correct
57 Correct 99 ms 18704 KB Output is correct
58 Correct 101 ms 19168 KB Output is correct
59 Correct 106 ms 18772 KB Output is correct
60 Correct 147 ms 19948 KB Output is correct
61 Correct 147 ms 20000 KB Output is correct
62 Correct 148 ms 20000 KB Output is correct
63 Correct 205 ms 22620 KB Output is correct
64 Correct 206 ms 22620 KB Output is correct
65 Correct 249 ms 22748 KB Output is correct
66 Correct 88 ms 19820 KB Output is correct
67 Correct 134 ms 20772 KB Output is correct
68 Correct 109 ms 20884 KB Output is correct
69 Correct 110 ms 20844 KB Output is correct
70 Correct 134 ms 20844 KB Output is correct
71 Correct 106 ms 20864 KB Output is correct
72 Correct 112 ms 20972 KB Output is correct
73 Correct 117 ms 20844 KB Output is correct
74 Correct 108 ms 20844 KB Output is correct
75 Correct 368 ms 27308 KB Output is correct
76 Correct 393 ms 27764 KB Output is correct
77 Correct 359 ms 28664 KB Output is correct
78 Correct 368 ms 28632 KB Output is correct
79 Correct 385 ms 27216 KB Output is correct
80 Correct 342 ms 28632 KB Output is correct
81 Correct 565 ms 31468 KB Output is correct
82 Correct 707 ms 31540 KB Output is correct
83 Correct 601 ms 31496 KB Output is correct
84 Correct 583 ms 31596 KB Output is correct
85 Correct 587 ms 31596 KB Output is correct
86 Correct 828 ms 31276 KB Output is correct
87 Correct 603 ms 33888 KB Output is correct
88 Correct 1273 ms 43120 KB Output is correct
89 Correct 1228 ms 42940 KB Output is correct
90 Correct 1280 ms 42940 KB Output is correct
91 Correct 1174 ms 43284 KB Output is correct
92 Correct 1253 ms 43028 KB Output is correct
93 Correct 542 ms 40848 KB Output is correct
94 Correct 478 ms 37812 KB Output is correct
95 Correct 533 ms 41068 KB Output is correct
96 Correct 541 ms 40812 KB Output is correct
97 Correct 532 ms 37688 KB Output is correct
98 Correct 497 ms 38764 KB Output is correct
99 Correct 579 ms 41068 KB Output is correct
100 Correct 515 ms 40836 KB Output is correct
101 Correct 518 ms 37876 KB Output is correct
102 Correct 623 ms 40940 KB Output is correct
103 Correct 558 ms 36812 KB Output is correct
104 Correct 567 ms 40980 KB Output is correct
105 Correct 307 ms 35692 KB Output is correct
106 Correct 399 ms 40300 KB Output is correct
107 Correct 394 ms 40300 KB Output is correct
108 Correct 387 ms 40300 KB Output is correct
109 Correct 394 ms 40300 KB Output is correct
110 Correct 402 ms 40300 KB Output is correct
111 Correct 392 ms 40300 KB Output is correct
112 Correct 389 ms 40428 KB Output is correct
113 Correct 399 ms 40320 KB Output is correct
114 Correct 399 ms 40324 KB Output is correct
115 Correct 412 ms 40428 KB Output is correct
116 Correct 426 ms 41144 KB Output is correct