Submission #49280

# Submission time Handle Problem Language Result Execution time Memory
49280 2018-05-24T18:00:26 Z zadrga Circle selection (APIO18_circle_selection) C++14
100 / 100
2032 ms 24272 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 300111

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

struct circle{
	ll x, y, r;
	int ind;
} c[maxn], a[maxn];

bool used[maxn];
int ans[maxn], order[maxn];
int n, cur_r, next_r;

bool operator<(circle a, circle b){
	if(a.x == b.x)	
		return a.y < b.y;

	return a.x < b.x;
}

bool comp(int x, int y){
	if(a[x].r == a[y].r)
		return a[x].ind < a[y].ind;

	return a[x].r > a[y].r;
}

void rescale(){
	cur_r = next_r;
	next_r = cur_r / 2;

	for(int i = 1; i <= n; i++){
		int cur = c[i].ind;
		c[i].x = a[cur].x / cur_r;
		c[i].y = a[cur].y / cur_r;
	}

	sort(c + 1, c + 1 + n);
}

bool intersection(circle &a, circle &b){
	ll dist_center = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
	ll dist_r = (a.r + b.r) * (a.r + b.r);
	return dist_center <= dist_r;
}

void solve(int cur){
	int pos_x = a[cur].x / cur_r;
	int pos_y = a[cur].y / cur_r;

	ans[cur] = cur;
	used[cur] = 1;

	for(int cur_x = pos_x - 2; cur_x <= pos_x + 2; cur_x++){
		int it = lower_bound(c + 1, c + 1 + n, (circle) {cur_x, pos_y - 2, -1, -1}) - c;
		while(it <= n && c[it].x == cur_x && c[it].y <= pos_y + 2){
			if(!used[c[it].ind] && intersection(a[c[it].ind], a[cur])){
				ans[c[it].ind] = cur;
				used[c[it].ind] = 1;
			}
			it++;
		}
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		ll x, y, r;
		scanf("%lld%lld%lld", &x, &y, &r);
		a[i] = c[i] = {x, y, r, i};
		order[i] = i;
	}
	
	sort(order + 1, order + 1 + n, comp);

	next_r = a[order[1]].r; 
	rescale();

	for(int i = 1; i <= n; i++){
		if(used[order[i]])
			continue;

		if(a[order[i]].r <= next_r)
			rescale();

		solve(order[i]);
	}

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

	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
circle_selection.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &x, &y, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 556 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 8 ms 1004 KB Output is correct
20 Correct 7 ms 1132 KB Output is correct
21 Correct 7 ms 1132 KB Output is correct
22 Correct 13 ms 1132 KB Output is correct
23 Correct 12 ms 1132 KB Output is correct
24 Correct 14 ms 1132 KB Output is correct
25 Correct 12 ms 1132 KB Output is correct
26 Correct 12 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 24076 KB Output is correct
2 Correct 324 ms 24272 KB Output is correct
3 Correct 341 ms 24272 KB Output is correct
4 Correct 324 ms 24272 KB Output is correct
5 Correct 676 ms 24272 KB Output is correct
6 Correct 737 ms 24272 KB Output is correct
7 Correct 794 ms 24272 KB Output is correct
8 Correct 751 ms 24272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 24272 KB Output is correct
2 Correct 502 ms 24272 KB Output is correct
3 Correct 1742 ms 24272 KB Output is correct
4 Correct 1713 ms 24272 KB Output is correct
5 Correct 1917 ms 24272 KB Output is correct
6 Correct 507 ms 24272 KB Output is correct
7 Correct 215 ms 24272 KB Output is correct
8 Correct 29 ms 24272 KB Output is correct
9 Correct 1789 ms 24272 KB Output is correct
10 Correct 997 ms 24272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 663 ms 24272 KB Output is correct
2 Correct 614 ms 24272 KB Output is correct
3 Correct 294 ms 24272 KB Output is correct
4 Correct 549 ms 24272 KB Output is correct
5 Correct 564 ms 24272 KB Output is correct
6 Correct 306 ms 24272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 556 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 8 ms 1004 KB Output is correct
20 Correct 7 ms 1132 KB Output is correct
21 Correct 7 ms 1132 KB Output is correct
22 Correct 13 ms 1132 KB Output is correct
23 Correct 12 ms 1132 KB Output is correct
24 Correct 14 ms 1132 KB Output is correct
25 Correct 12 ms 1132 KB Output is correct
26 Correct 12 ms 1132 KB Output is correct
27 Correct 18 ms 24272 KB Output is correct
28 Correct 11 ms 24272 KB Output is correct
29 Correct 11 ms 24272 KB Output is correct
30 Correct 26 ms 24272 KB Output is correct
31 Correct 24 ms 24272 KB Output is correct
32 Correct 27 ms 24272 KB Output is correct
33 Correct 103 ms 24272 KB Output is correct
34 Correct 107 ms 24272 KB Output is correct
35 Correct 341 ms 24272 KB Output is correct
36 Correct 451 ms 24272 KB Output is correct
37 Correct 423 ms 24272 KB Output is correct
38 Correct 426 ms 24272 KB Output is correct
39 Correct 457 ms 24272 KB Output is correct
40 Correct 420 ms 24272 KB Output is correct
41 Correct 478 ms 24272 KB Output is correct
42 Correct 171 ms 24272 KB Output is correct
43 Correct 164 ms 24272 KB Output is correct
44 Correct 185 ms 24272 KB Output is correct
45 Correct 165 ms 24272 KB Output is correct
46 Correct 185 ms 24272 KB Output is correct
47 Correct 183 ms 24272 KB Output is correct
48 Correct 170 ms 24272 KB Output is correct
49 Correct 158 ms 24272 KB Output is correct
50 Correct 171 ms 24272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 536 KB Output is correct
4 Correct 2 ms 536 KB Output is correct
5 Correct 2 ms 536 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 556 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 620 KB Output is correct
18 Correct 3 ms 620 KB Output is correct
19 Correct 8 ms 1004 KB Output is correct
20 Correct 7 ms 1132 KB Output is correct
21 Correct 7 ms 1132 KB Output is correct
22 Correct 13 ms 1132 KB Output is correct
23 Correct 12 ms 1132 KB Output is correct
24 Correct 14 ms 1132 KB Output is correct
25 Correct 12 ms 1132 KB Output is correct
26 Correct 12 ms 1132 KB Output is correct
27 Correct 308 ms 24076 KB Output is correct
28 Correct 324 ms 24272 KB Output is correct
29 Correct 341 ms 24272 KB Output is correct
30 Correct 324 ms 24272 KB Output is correct
31 Correct 676 ms 24272 KB Output is correct
32 Correct 737 ms 24272 KB Output is correct
33 Correct 794 ms 24272 KB Output is correct
34 Correct 751 ms 24272 KB Output is correct
35 Correct 2 ms 24272 KB Output is correct
36 Correct 502 ms 24272 KB Output is correct
37 Correct 1742 ms 24272 KB Output is correct
38 Correct 1713 ms 24272 KB Output is correct
39 Correct 1917 ms 24272 KB Output is correct
40 Correct 507 ms 24272 KB Output is correct
41 Correct 215 ms 24272 KB Output is correct
42 Correct 29 ms 24272 KB Output is correct
43 Correct 1789 ms 24272 KB Output is correct
44 Correct 997 ms 24272 KB Output is correct
45 Correct 663 ms 24272 KB Output is correct
46 Correct 614 ms 24272 KB Output is correct
47 Correct 294 ms 24272 KB Output is correct
48 Correct 549 ms 24272 KB Output is correct
49 Correct 564 ms 24272 KB Output is correct
50 Correct 306 ms 24272 KB Output is correct
51 Correct 18 ms 24272 KB Output is correct
52 Correct 11 ms 24272 KB Output is correct
53 Correct 11 ms 24272 KB Output is correct
54 Correct 26 ms 24272 KB Output is correct
55 Correct 24 ms 24272 KB Output is correct
56 Correct 27 ms 24272 KB Output is correct
57 Correct 103 ms 24272 KB Output is correct
58 Correct 107 ms 24272 KB Output is correct
59 Correct 341 ms 24272 KB Output is correct
60 Correct 451 ms 24272 KB Output is correct
61 Correct 423 ms 24272 KB Output is correct
62 Correct 426 ms 24272 KB Output is correct
63 Correct 457 ms 24272 KB Output is correct
64 Correct 420 ms 24272 KB Output is correct
65 Correct 478 ms 24272 KB Output is correct
66 Correct 171 ms 24272 KB Output is correct
67 Correct 164 ms 24272 KB Output is correct
68 Correct 185 ms 24272 KB Output is correct
69 Correct 165 ms 24272 KB Output is correct
70 Correct 185 ms 24272 KB Output is correct
71 Correct 183 ms 24272 KB Output is correct
72 Correct 170 ms 24272 KB Output is correct
73 Correct 158 ms 24272 KB Output is correct
74 Correct 171 ms 24272 KB Output is correct
75 Correct 1244 ms 24272 KB Output is correct
76 Correct 445 ms 24272 KB Output is correct
77 Correct 482 ms 24272 KB Output is correct
78 Correct 345 ms 24272 KB Output is correct
79 Correct 1405 ms 24272 KB Output is correct
80 Correct 330 ms 24272 KB Output is correct
81 Correct 1522 ms 24272 KB Output is correct
82 Correct 1512 ms 24272 KB Output is correct
83 Correct 1704 ms 24272 KB Output is correct
84 Correct 1676 ms 24272 KB Output is correct
85 Correct 1731 ms 24272 KB Output is correct
86 Correct 1459 ms 24272 KB Output is correct
87 Correct 1819 ms 24272 KB Output is correct
88 Correct 1907 ms 24272 KB Output is correct
89 Correct 2032 ms 24272 KB Output is correct
90 Correct 1925 ms 24272 KB Output is correct
91 Correct 2028 ms 24272 KB Output is correct
92 Correct 1829 ms 24272 KB Output is correct
93 Correct 893 ms 24272 KB Output is correct
94 Correct 1100 ms 24272 KB Output is correct
95 Correct 940 ms 24272 KB Output is correct
96 Correct 987 ms 24272 KB Output is correct
97 Correct 1206 ms 24272 KB Output is correct
98 Correct 852 ms 24272 KB Output is correct
99 Correct 890 ms 24272 KB Output is correct
100 Correct 726 ms 24272 KB Output is correct
101 Correct 988 ms 24272 KB Output is correct
102 Correct 883 ms 24272 KB Output is correct
103 Correct 1187 ms 24272 KB Output is correct
104 Correct 866 ms 24272 KB Output is correct
105 Correct 408 ms 24272 KB Output is correct
106 Correct 531 ms 24272 KB Output is correct
107 Correct 510 ms 24272 KB Output is correct
108 Correct 541 ms 24272 KB Output is correct
109 Correct 538 ms 24272 KB Output is correct
110 Correct 512 ms 24272 KB Output is correct
111 Correct 522 ms 24272 KB Output is correct
112 Correct 537 ms 24272 KB Output is correct
113 Correct 514 ms 24272 KB Output is correct
114 Correct 489 ms 24272 KB Output is correct
115 Correct 567 ms 24272 KB Output is correct
116 Correct 518 ms 24272 KB Output is correct