#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
bool intersect(ll x1, ll y1, ll x2, ll y2, ll r1, ll r2) {
ll dx = abs(x1 - x2);
ll dy = abs(y1 - y2);
ll dt = r1 + r2;
if (dt * dt >= dx * dx + dy * dy)
return true;
return false;
}
int main() {
fastIO();
int N;
cin>>N;
vector<pair<ii, ll>> cr(N);
// {{x, y}, r}
multiset<pair<ii, ii>> all;
// {{r, -id}, {x, y}}
map<ll, set<pair<ll, ii>>> allx; // maps x coord to all {y, {r, id}}
for (int i = 0; i < N; i++) {
ll x, y, r;
cin>>x>>y>>r;
all.insert({{r, -i}, {x, y}});
allx[x].insert({y, {r, i}});
}
vi par(N, -1);
int rem = N;
while (rem > 0) {
auto it = --all.end();
ll r = (*it).fi.fi;
int id = -(*it).fi.se;
ll x = (*it).se.fi;
ll y = (*it).se.se;
// cout<<"at "<<id<<endl;
// consider all from x in x-2r to x+2r, y in y-2r to r+2r
auto it2 = allx.lower_bound(x - 2 * r);
while (it2 != allx.end() && (*it2).fi <= x + 2 * r) {
// do another search inside
ll cx = (*it2).fi;
vector<pair<ll, ii>> toremove;
auto it3 = allx[cx].lower_bound({y - 2 * r, {-1, -1}});
while (it3 != allx[cx].end() && (*it3).fi <= y + 2 * r) {
ll cy = (*it3).fi;
ll cr = (*it3).se.fi;
int cid = (*it3).se.se;
if (intersect(x, y, cx, cy, r, cr)) {
toremove.pb(*it3);
}
it3++;
}
for (pair<ll, ii> p : toremove) {
par[p.se.se] = id;
// cout<<"erased "<<p.se.se<<endl;
allx[cx].erase(p);
all.erase({{p.se.fi, -p.se.se}, {cx, p.fi}});
rem--;
}
it2++;
}
}
// cout<<"ANSWER: ";
for (int x : par)
cout<<(x + 1)<<" ";
cout<<endl;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:63:9: warning: unused variable 'cid' [-Wunused-variable]
63 | int cid = (*it3).se.se;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
508 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
9 ms |
1740 KB |
Output is correct |
20 |
Correct |
7 ms |
1628 KB |
Output is correct |
21 |
Correct |
8 ms |
1628 KB |
Output is correct |
22 |
Correct |
10 ms |
1780 KB |
Output is correct |
23 |
Correct |
33 ms |
1624 KB |
Output is correct |
24 |
Correct |
11 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1788 KB |
Output is correct |
26 |
Correct |
7 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
722 ms |
82216 KB |
Output is correct |
2 |
Correct |
813 ms |
82196 KB |
Output is correct |
3 |
Correct |
740 ms |
82000 KB |
Output is correct |
4 |
Correct |
724 ms |
82268 KB |
Output is correct |
5 |
Correct |
653 ms |
72788 KB |
Output is correct |
6 |
Correct |
850 ms |
82048 KB |
Output is correct |
7 |
Correct |
805 ms |
80480 KB |
Output is correct |
8 |
Correct |
785 ms |
81236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
744 ms |
27444 KB |
Output is correct |
3 |
Correct |
2705 ms |
82072 KB |
Output is correct |
4 |
Correct |
2677 ms |
82076 KB |
Output is correct |
5 |
Execution timed out |
3083 ms |
77908 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1613 ms |
82256 KB |
Output is correct |
2 |
Correct |
617 ms |
82040 KB |
Output is correct |
3 |
Execution timed out |
3062 ms |
80276 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
508 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
9 ms |
1740 KB |
Output is correct |
20 |
Correct |
7 ms |
1628 KB |
Output is correct |
21 |
Correct |
8 ms |
1628 KB |
Output is correct |
22 |
Correct |
10 ms |
1780 KB |
Output is correct |
23 |
Correct |
33 ms |
1624 KB |
Output is correct |
24 |
Correct |
11 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1788 KB |
Output is correct |
26 |
Correct |
7 ms |
1628 KB |
Output is correct |
27 |
Correct |
13 ms |
3164 KB |
Output is correct |
28 |
Correct |
13 ms |
3132 KB |
Output is correct |
29 |
Correct |
15 ms |
3160 KB |
Output is correct |
30 |
Correct |
33 ms |
3120 KB |
Output is correct |
31 |
Correct |
16 ms |
3164 KB |
Output is correct |
32 |
Correct |
21 ms |
3164 KB |
Output is correct |
33 |
Correct |
200 ms |
27472 KB |
Output is correct |
34 |
Correct |
184 ms |
27652 KB |
Output is correct |
35 |
Correct |
220 ms |
27428 KB |
Output is correct |
36 |
Correct |
274 ms |
27472 KB |
Output is correct |
37 |
Correct |
295 ms |
27576 KB |
Output is correct |
38 |
Correct |
340 ms |
27472 KB |
Output is correct |
39 |
Correct |
492 ms |
18116 KB |
Output is correct |
40 |
Correct |
476 ms |
18256 KB |
Output is correct |
41 |
Correct |
465 ms |
18260 KB |
Output is correct |
42 |
Correct |
161 ms |
18260 KB |
Output is correct |
43 |
Correct |
166 ms |
27736 KB |
Output is correct |
44 |
Correct |
170 ms |
27476 KB |
Output is correct |
45 |
Correct |
172 ms |
27476 KB |
Output is correct |
46 |
Correct |
166 ms |
27728 KB |
Output is correct |
47 |
Correct |
182 ms |
27544 KB |
Output is correct |
48 |
Correct |
167 ms |
27472 KB |
Output is correct |
49 |
Correct |
171 ms |
27728 KB |
Output is correct |
50 |
Correct |
171 ms |
27488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
508 KB |
Output is correct |
17 |
Correct |
2 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
9 ms |
1740 KB |
Output is correct |
20 |
Correct |
7 ms |
1628 KB |
Output is correct |
21 |
Correct |
8 ms |
1628 KB |
Output is correct |
22 |
Correct |
10 ms |
1780 KB |
Output is correct |
23 |
Correct |
33 ms |
1624 KB |
Output is correct |
24 |
Correct |
11 ms |
1628 KB |
Output is correct |
25 |
Correct |
6 ms |
1788 KB |
Output is correct |
26 |
Correct |
7 ms |
1628 KB |
Output is correct |
27 |
Correct |
722 ms |
82216 KB |
Output is correct |
28 |
Correct |
813 ms |
82196 KB |
Output is correct |
29 |
Correct |
740 ms |
82000 KB |
Output is correct |
30 |
Correct |
724 ms |
82268 KB |
Output is correct |
31 |
Correct |
653 ms |
72788 KB |
Output is correct |
32 |
Correct |
850 ms |
82048 KB |
Output is correct |
33 |
Correct |
805 ms |
80480 KB |
Output is correct |
34 |
Correct |
785 ms |
81236 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
744 ms |
27444 KB |
Output is correct |
37 |
Correct |
2705 ms |
82072 KB |
Output is correct |
38 |
Correct |
2677 ms |
82076 KB |
Output is correct |
39 |
Execution timed out |
3083 ms |
77908 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |