bool home = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int) 3e5 + 7;
const int INF = (int) 1e9 + 7;
int n;
struct Circle {
int x;
int y;
int r;
};
bool doIntersect(Circle a, Circle b) {
/// dist <= a.r + b.r
/// dist ^ 2 <= (a.r + b.r) ^ 2
return 1LL * (a.x - b.x) * (a.x - b.x) + 1LL * (a.y - b.y) * (a.y - b.y) <= 1LL * (a.r + b.r) * (a.r + b.r);
}
Circle circles[N];
int ret[N];
map<pair<int, int>, vector<int>> guysAtPosition;
bool cmp(int i, int j) {
if (circles[i].r == circles[j].r) {
return i < j;
} else {
return circles[i].r > circles[j].r;
}
}
set<int, decltype(cmp)*> s(cmp);
int r_divide_glob;
void place(int r_divide, set<int, decltype(cmp)*>& s) {
r_divide_glob = r_divide;
guysAtPosition.clear();
for (auto &i : s) {
guysAtPosition[{circles[i].x / r_divide, circles[i].y / r_divide}].push_back(i);
}
}
void elim(int i, set<int, decltype(cmp)*>& s) {
int x = circles[i].x / r_divide_glob, y = circles[i].y / r_divide_glob;
for (int x2 = x - 2; x2 <= x + 2; x2++) {
for (int y2 = y - 2; y2 <= y + 2; y2++) {
pair<int, int> it = {x2, y2};
if (!guysAtPosition.count(it)) {
continue;
}
for (auto &j : guysAtPosition[it]) {
if (ret[j] == 0 && doIntersect(circles[i], circles[j])) {
ret[j] = i;
s.erase(j);
}
}
}
}
}
int main() {
if (home == 0) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
} else {
freopen ("input.txt", "r", stdin);
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
circles[i].x += INF;
circles[i].y += INF;
}
for (int i = 1; i <= n; i++) {
s.insert(i);
}
int max_radius = circles[1].r;
for (int i = 2; i <= n; i++) {
max_radius = max(max_radius, circles[i].r);
}
place(max_radius, s);
while (!s.empty()) {
int i = *s.begin();
if (circles[i].r <= max_radius / 2) {
max_radius = circles[i].r;
place(max_radius, s);
}
elim(i, s);
}
for (int i = 1; i <= n; i++) {
cout << ret[i] << " ";
}
cout << "\n";
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:73:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen ("input.txt", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
5 ms |
852 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
4 ms |
764 KB |
Output is correct |
22 |
Correct |
13 ms |
1280 KB |
Output is correct |
23 |
Correct |
14 ms |
1236 KB |
Output is correct |
24 |
Correct |
13 ms |
1324 KB |
Output is correct |
25 |
Correct |
12 ms |
1348 KB |
Output is correct |
26 |
Correct |
14 ms |
1328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
21244 KB |
Output is correct |
2 |
Correct |
462 ms |
21336 KB |
Output is correct |
3 |
Correct |
484 ms |
22620 KB |
Output is correct |
4 |
Correct |
480 ms |
21772 KB |
Output is correct |
5 |
Correct |
629 ms |
23712 KB |
Output is correct |
6 |
Correct |
1119 ms |
37384 KB |
Output is correct |
7 |
Correct |
718 ms |
25304 KB |
Output is correct |
8 |
Correct |
784 ms |
27512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
511 ms |
18032 KB |
Output is correct |
3 |
Correct |
2102 ms |
53948 KB |
Output is correct |
4 |
Correct |
2090 ms |
53908 KB |
Output is correct |
5 |
Correct |
2171 ms |
47276 KB |
Output is correct |
6 |
Correct |
806 ms |
23572 KB |
Output is correct |
7 |
Correct |
339 ms |
12804 KB |
Output is correct |
8 |
Correct |
37 ms |
2920 KB |
Output is correct |
9 |
Correct |
2559 ms |
53004 KB |
Output is correct |
10 |
Correct |
2165 ms |
46012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1541 ms |
53848 KB |
Output is correct |
2 |
Correct |
1180 ms |
54000 KB |
Output is correct |
3 |
Correct |
811 ms |
30780 KB |
Output is correct |
4 |
Correct |
1188 ms |
54424 KB |
Output is correct |
5 |
Correct |
1170 ms |
54528 KB |
Output is correct |
6 |
Correct |
598 ms |
25000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
5 ms |
852 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
4 ms |
764 KB |
Output is correct |
22 |
Correct |
13 ms |
1280 KB |
Output is correct |
23 |
Correct |
14 ms |
1236 KB |
Output is correct |
24 |
Correct |
13 ms |
1324 KB |
Output is correct |
25 |
Correct |
12 ms |
1348 KB |
Output is correct |
26 |
Correct |
14 ms |
1328 KB |
Output is correct |
27 |
Correct |
8 ms |
1028 KB |
Output is correct |
28 |
Correct |
7 ms |
980 KB |
Output is correct |
29 |
Correct |
8 ms |
1064 KB |
Output is correct |
30 |
Correct |
29 ms |
2056 KB |
Output is correct |
31 |
Correct |
28 ms |
2040 KB |
Output is correct |
32 |
Correct |
27 ms |
2004 KB |
Output is correct |
33 |
Correct |
103 ms |
7644 KB |
Output is correct |
34 |
Correct |
104 ms |
7752 KB |
Output is correct |
35 |
Correct |
108 ms |
7316 KB |
Output is correct |
36 |
Correct |
448 ms |
18124 KB |
Output is correct |
37 |
Correct |
488 ms |
18016 KB |
Output is correct |
38 |
Correct |
492 ms |
18052 KB |
Output is correct |
39 |
Correct |
417 ms |
16416 KB |
Output is correct |
40 |
Correct |
411 ms |
17160 KB |
Output is correct |
41 |
Correct |
440 ms |
16968 KB |
Output is correct |
42 |
Correct |
366 ms |
18464 KB |
Output is correct |
43 |
Correct |
327 ms |
18380 KB |
Output is correct |
44 |
Correct |
329 ms |
18392 KB |
Output is correct |
45 |
Correct |
329 ms |
18380 KB |
Output is correct |
46 |
Correct |
331 ms |
18308 KB |
Output is correct |
47 |
Correct |
337 ms |
18312 KB |
Output is correct |
48 |
Correct |
330 ms |
18368 KB |
Output is correct |
49 |
Correct |
329 ms |
18428 KB |
Output is correct |
50 |
Correct |
328 ms |
18364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
5 ms |
852 KB |
Output is correct |
20 |
Correct |
4 ms |
724 KB |
Output is correct |
21 |
Correct |
4 ms |
764 KB |
Output is correct |
22 |
Correct |
13 ms |
1280 KB |
Output is correct |
23 |
Correct |
14 ms |
1236 KB |
Output is correct |
24 |
Correct |
13 ms |
1324 KB |
Output is correct |
25 |
Correct |
12 ms |
1348 KB |
Output is correct |
26 |
Correct |
14 ms |
1328 KB |
Output is correct |
27 |
Correct |
452 ms |
21244 KB |
Output is correct |
28 |
Correct |
462 ms |
21336 KB |
Output is correct |
29 |
Correct |
484 ms |
22620 KB |
Output is correct |
30 |
Correct |
480 ms |
21772 KB |
Output is correct |
31 |
Correct |
629 ms |
23712 KB |
Output is correct |
32 |
Correct |
1119 ms |
37384 KB |
Output is correct |
33 |
Correct |
718 ms |
25304 KB |
Output is correct |
34 |
Correct |
784 ms |
27512 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
511 ms |
18032 KB |
Output is correct |
37 |
Correct |
2102 ms |
53948 KB |
Output is correct |
38 |
Correct |
2090 ms |
53908 KB |
Output is correct |
39 |
Correct |
2171 ms |
47276 KB |
Output is correct |
40 |
Correct |
806 ms |
23572 KB |
Output is correct |
41 |
Correct |
339 ms |
12804 KB |
Output is correct |
42 |
Correct |
37 ms |
2920 KB |
Output is correct |
43 |
Correct |
2559 ms |
53004 KB |
Output is correct |
44 |
Correct |
2165 ms |
46012 KB |
Output is correct |
45 |
Correct |
1541 ms |
53848 KB |
Output is correct |
46 |
Correct |
1180 ms |
54000 KB |
Output is correct |
47 |
Correct |
811 ms |
30780 KB |
Output is correct |
48 |
Correct |
1188 ms |
54424 KB |
Output is correct |
49 |
Correct |
1170 ms |
54528 KB |
Output is correct |
50 |
Correct |
598 ms |
25000 KB |
Output is correct |
51 |
Correct |
8 ms |
1028 KB |
Output is correct |
52 |
Correct |
7 ms |
980 KB |
Output is correct |
53 |
Correct |
8 ms |
1064 KB |
Output is correct |
54 |
Correct |
29 ms |
2056 KB |
Output is correct |
55 |
Correct |
28 ms |
2040 KB |
Output is correct |
56 |
Correct |
27 ms |
2004 KB |
Output is correct |
57 |
Correct |
103 ms |
7644 KB |
Output is correct |
58 |
Correct |
104 ms |
7752 KB |
Output is correct |
59 |
Correct |
108 ms |
7316 KB |
Output is correct |
60 |
Correct |
448 ms |
18124 KB |
Output is correct |
61 |
Correct |
488 ms |
18016 KB |
Output is correct |
62 |
Correct |
492 ms |
18052 KB |
Output is correct |
63 |
Correct |
417 ms |
16416 KB |
Output is correct |
64 |
Correct |
411 ms |
17160 KB |
Output is correct |
65 |
Correct |
440 ms |
16968 KB |
Output is correct |
66 |
Correct |
366 ms |
18464 KB |
Output is correct |
67 |
Correct |
327 ms |
18380 KB |
Output is correct |
68 |
Correct |
329 ms |
18392 KB |
Output is correct |
69 |
Correct |
329 ms |
18380 KB |
Output is correct |
70 |
Correct |
331 ms |
18308 KB |
Output is correct |
71 |
Correct |
337 ms |
18312 KB |
Output is correct |
72 |
Correct |
330 ms |
18368 KB |
Output is correct |
73 |
Correct |
329 ms |
18428 KB |
Output is correct |
74 |
Correct |
328 ms |
18364 KB |
Output is correct |
75 |
Correct |
551 ms |
21784 KB |
Output is correct |
76 |
Correct |
563 ms |
22164 KB |
Output is correct |
77 |
Correct |
434 ms |
23004 KB |
Output is correct |
78 |
Correct |
414 ms |
22684 KB |
Output is correct |
79 |
Correct |
681 ms |
21852 KB |
Output is correct |
80 |
Correct |
469 ms |
22648 KB |
Output is correct |
81 |
Correct |
2031 ms |
54472 KB |
Output is correct |
82 |
Correct |
1874 ms |
54424 KB |
Output is correct |
83 |
Correct |
1902 ms |
54504 KB |
Output is correct |
84 |
Correct |
2143 ms |
54348 KB |
Output is correct |
85 |
Correct |
1969 ms |
54400 KB |
Output is correct |
86 |
Correct |
1924 ms |
54464 KB |
Output is correct |
87 |
Correct |
2283 ms |
54304 KB |
Output is correct |
88 |
Correct |
1510 ms |
49620 KB |
Output is correct |
89 |
Correct |
1546 ms |
49584 KB |
Output is correct |
90 |
Correct |
1561 ms |
49556 KB |
Output is correct |
91 |
Correct |
1514 ms |
49532 KB |
Output is correct |
92 |
Correct |
1533 ms |
49488 KB |
Output is correct |
93 |
Correct |
1423 ms |
54380 KB |
Output is correct |
94 |
Correct |
1666 ms |
54084 KB |
Output is correct |
95 |
Correct |
1402 ms |
54520 KB |
Output is correct |
96 |
Correct |
1534 ms |
54408 KB |
Output is correct |
97 |
Correct |
2155 ms |
54436 KB |
Output is correct |
98 |
Correct |
1258 ms |
42444 KB |
Output is correct |
99 |
Correct |
1527 ms |
54348 KB |
Output is correct |
100 |
Correct |
1310 ms |
54436 KB |
Output is correct |
101 |
Correct |
1576 ms |
47528 KB |
Output is correct |
102 |
Correct |
1498 ms |
53988 KB |
Output is correct |
103 |
Correct |
2051 ms |
53952 KB |
Output is correct |
104 |
Correct |
1441 ms |
54388 KB |
Output is correct |
105 |
Correct |
1299 ms |
54064 KB |
Output is correct |
106 |
Correct |
1142 ms |
52136 KB |
Output is correct |
107 |
Correct |
1150 ms |
52472 KB |
Output is correct |
108 |
Correct |
1139 ms |
52248 KB |
Output is correct |
109 |
Correct |
1159 ms |
52244 KB |
Output is correct |
110 |
Correct |
1156 ms |
52284 KB |
Output is correct |
111 |
Correct |
1153 ms |
52260 KB |
Output is correct |
112 |
Correct |
1188 ms |
52324 KB |
Output is correct |
113 |
Correct |
1136 ms |
52416 KB |
Output is correct |
114 |
Correct |
1145 ms |
52476 KB |
Output is correct |
115 |
Correct |
1152 ms |
52400 KB |
Output is correct |
116 |
Correct |
1104 ms |
52308 KB |
Output is correct |