#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define task "main"
using namespace std;
const int N = (int)3e5 + 10;
struct Circle {
int x, y, r, i;
Circle(int _x = 0, int _y = 0, int _r = 0, int _i = 0) {
x = _x, y = _y, r = _r, i = _i;
}
} circles[N];
int n;
int res[N];
bool cmp(const Circle &a, const Circle &b){
if (a.r == b.r) return a.i < b.i;
return a.r > b.r;
}
bool intersect(const Circle &a, const Circle &b) {
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);
}
void solve() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
circles[i].i = i;
}
sort (circles, circles + n, cmp);
memset(res, -1, sizeof res);
for (int lg = 30; lg >= 0; --lg) {
int r = (1 << lg);
map<pii, vector<int> > grid;
bool found = false;
for (int i = 0; i < n; ++i) {
if (res[circles[i].i] == -1 && circles[i].r >= r / 2 && circles[i].r <= r) {
found = true;
break;
}
}
for (int i = 0; i < n; ++i) {
if (res[circles[i].i] == -1) {
grid[pii(circles[i].x / r, circles[i].y / r)].push_back(i);
}
}
for (int i = 0; i < n; ++i) {
Circle &cur = circles[i];
if (cur.r < r / 2) break;
if (res[cur.i] != -1 || cur.r > r) continue;
for(int x = cur.x / r - 2; x <= cur.x / r + 2; ++x) {
for(int y = cur.y / r - 2; y <= cur.y / r + 2; ++y) {
if (grid.find(pii(x, y)) == grid.end()) continue;
vector<int> &candidates = grid[pii(x, y)];
for (int i = (int)candidates.size() - 1; i >= 0; --i) {
int c = candidates[i];
if (res[circles[c].i] == -1 && intersect(circles[c], cur)) {
res[circles[c].i] = cur.i;
swap (candidates[i], candidates.back());
candidates.pop_back();
}
}
}
}
}
}
for(int i = 0; i < n; i++) cout << res[i] + 1 << ' ';
}
int main() {
#ifdef LOCAL
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
Compilation message
circle_selection.cpp: In function 'void solve()':
circle_selection.cpp:41:14: warning: variable 'found' set but not used [-Wunused-but-set-variable]
41 | bool found = false;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6256 KB |
Output is correct |
2 |
Correct |
3 ms |
6212 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6228 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6244 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6180 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
6232 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
3 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6320 KB |
Output is correct |
15 |
Correct |
3 ms |
6192 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6340 KB |
Output is correct |
21 |
Correct |
5 ms |
6344 KB |
Output is correct |
22 |
Correct |
24 ms |
7024 KB |
Output is correct |
23 |
Correct |
21 ms |
6996 KB |
Output is correct |
24 |
Correct |
21 ms |
7040 KB |
Output is correct |
25 |
Correct |
23 ms |
7004 KB |
Output is correct |
26 |
Correct |
21 ms |
7004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
16228 KB |
Output is correct |
2 |
Correct |
142 ms |
17156 KB |
Output is correct |
3 |
Correct |
140 ms |
16568 KB |
Output is correct |
4 |
Correct |
132 ms |
15248 KB |
Output is correct |
5 |
Correct |
327 ms |
15600 KB |
Output is correct |
6 |
Correct |
887 ms |
25656 KB |
Output is correct |
7 |
Correct |
377 ms |
16432 KB |
Output is correct |
8 |
Correct |
507 ms |
18544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6232 KB |
Output is correct |
2 |
Correct |
522 ms |
20652 KB |
Output is correct |
3 |
Correct |
2457 ms |
49228 KB |
Output is correct |
4 |
Correct |
2485 ms |
49248 KB |
Output is correct |
5 |
Correct |
1656 ms |
43836 KB |
Output is correct |
6 |
Correct |
664 ms |
24668 KB |
Output is correct |
7 |
Correct |
306 ms |
15996 KB |
Output is correct |
8 |
Correct |
56 ms |
8240 KB |
Output is correct |
9 |
Correct |
2177 ms |
48332 KB |
Output is correct |
10 |
Correct |
1494 ms |
40992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2693 ms |
49232 KB |
Output is correct |
2 |
Execution timed out |
3033 ms |
46596 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6256 KB |
Output is correct |
2 |
Correct |
3 ms |
6212 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6228 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6244 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6180 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
6232 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
3 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6320 KB |
Output is correct |
15 |
Correct |
3 ms |
6192 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6340 KB |
Output is correct |
21 |
Correct |
5 ms |
6344 KB |
Output is correct |
22 |
Correct |
24 ms |
7024 KB |
Output is correct |
23 |
Correct |
21 ms |
6996 KB |
Output is correct |
24 |
Correct |
21 ms |
7040 KB |
Output is correct |
25 |
Correct |
23 ms |
7004 KB |
Output is correct |
26 |
Correct |
21 ms |
7004 KB |
Output is correct |
27 |
Correct |
6 ms |
6748 KB |
Output is correct |
28 |
Correct |
6 ms |
6744 KB |
Output is correct |
29 |
Correct |
6 ms |
6748 KB |
Output is correct |
30 |
Correct |
46 ms |
7696 KB |
Output is correct |
31 |
Correct |
40 ms |
7712 KB |
Output is correct |
32 |
Correct |
43 ms |
7708 KB |
Output is correct |
33 |
Correct |
59 ms |
9992 KB |
Output is correct |
34 |
Correct |
58 ms |
10036 KB |
Output is correct |
35 |
Correct |
49 ms |
10432 KB |
Output is correct |
36 |
Correct |
581 ms |
20384 KB |
Output is correct |
37 |
Correct |
592 ms |
20540 KB |
Output is correct |
38 |
Correct |
588 ms |
20508 KB |
Output is correct |
39 |
Correct |
298 ms |
14148 KB |
Output is correct |
40 |
Correct |
299 ms |
14092 KB |
Output is correct |
41 |
Correct |
306 ms |
14048 KB |
Output is correct |
42 |
Correct |
223 ms |
14996 KB |
Output is correct |
43 |
Correct |
504 ms |
20056 KB |
Output is correct |
44 |
Correct |
513 ms |
20192 KB |
Output is correct |
45 |
Correct |
484 ms |
20172 KB |
Output is correct |
46 |
Correct |
493 ms |
20460 KB |
Output is correct |
47 |
Correct |
495 ms |
20116 KB |
Output is correct |
48 |
Correct |
476 ms |
20148 KB |
Output is correct |
49 |
Correct |
491 ms |
20364 KB |
Output is correct |
50 |
Correct |
481 ms |
20228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6256 KB |
Output is correct |
2 |
Correct |
3 ms |
6212 KB |
Output is correct |
3 |
Correct |
3 ms |
6236 KB |
Output is correct |
4 |
Correct |
3 ms |
6228 KB |
Output is correct |
5 |
Correct |
2 ms |
6236 KB |
Output is correct |
6 |
Correct |
3 ms |
6244 KB |
Output is correct |
7 |
Correct |
3 ms |
6236 KB |
Output is correct |
8 |
Correct |
3 ms |
6180 KB |
Output is correct |
9 |
Correct |
3 ms |
6236 KB |
Output is correct |
10 |
Correct |
2 ms |
6232 KB |
Output is correct |
11 |
Correct |
3 ms |
6236 KB |
Output is correct |
12 |
Correct |
3 ms |
6236 KB |
Output is correct |
13 |
Correct |
3 ms |
6236 KB |
Output is correct |
14 |
Correct |
3 ms |
6320 KB |
Output is correct |
15 |
Correct |
3 ms |
6192 KB |
Output is correct |
16 |
Correct |
3 ms |
6236 KB |
Output is correct |
17 |
Correct |
3 ms |
6236 KB |
Output is correct |
18 |
Correct |
3 ms |
6236 KB |
Output is correct |
19 |
Correct |
5 ms |
6492 KB |
Output is correct |
20 |
Correct |
5 ms |
6340 KB |
Output is correct |
21 |
Correct |
5 ms |
6344 KB |
Output is correct |
22 |
Correct |
24 ms |
7024 KB |
Output is correct |
23 |
Correct |
21 ms |
6996 KB |
Output is correct |
24 |
Correct |
21 ms |
7040 KB |
Output is correct |
25 |
Correct |
23 ms |
7004 KB |
Output is correct |
26 |
Correct |
21 ms |
7004 KB |
Output is correct |
27 |
Correct |
142 ms |
16228 KB |
Output is correct |
28 |
Correct |
142 ms |
17156 KB |
Output is correct |
29 |
Correct |
140 ms |
16568 KB |
Output is correct |
30 |
Correct |
132 ms |
15248 KB |
Output is correct |
31 |
Correct |
327 ms |
15600 KB |
Output is correct |
32 |
Correct |
887 ms |
25656 KB |
Output is correct |
33 |
Correct |
377 ms |
16432 KB |
Output is correct |
34 |
Correct |
507 ms |
18544 KB |
Output is correct |
35 |
Correct |
3 ms |
6232 KB |
Output is correct |
36 |
Correct |
522 ms |
20652 KB |
Output is correct |
37 |
Correct |
2457 ms |
49228 KB |
Output is correct |
38 |
Correct |
2485 ms |
49248 KB |
Output is correct |
39 |
Correct |
1656 ms |
43836 KB |
Output is correct |
40 |
Correct |
664 ms |
24668 KB |
Output is correct |
41 |
Correct |
306 ms |
15996 KB |
Output is correct |
42 |
Correct |
56 ms |
8240 KB |
Output is correct |
43 |
Correct |
2177 ms |
48332 KB |
Output is correct |
44 |
Correct |
1494 ms |
40992 KB |
Output is correct |
45 |
Correct |
2693 ms |
49232 KB |
Output is correct |
46 |
Execution timed out |
3033 ms |
46596 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |