#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
inline long long sq(long long x) { return x * x; }
typedef struct Circle{
int x, y;
int r;
int i;
Circle(int i_, int x_, int y_, int r_){ i = i_, x = x_, y = y_, r = r_; }
bool meet(const Circle &c) const{
return (sq((long long) (x - c.x)) + sq((long long) (y - c.y)) <= sq((long long) (r + c.r)));
}
bool operator < (const Circle &c) const{
if (r != c.r) return r > c.r;
return i < c.i;
}
} Circle;
vector<Circle> L;
set<pii> S; //bst w/ x-coord & index
int ans[300000];
bool vis[300000];
int N;
int input(){
scanf("%d", &N);
int minr = 1<<30;
int maxr = -1;
bool ally0 = 1;
int x, y, r;
for (int i=0; i<N; i++){
scanf("%d%d%d", &x, &y, &r);
L.push_back(Circle(i, x, y, r));
minr = min(minr, r);
maxr = max(maxr, r);
if (y != 0) ally0 = 0;
}
if (N <= 5000) return 1;
if (ally0) return 2;
if (minr == maxr) return 4;
return 3; // we skip sub5/6 we assume sub3
}
void sub1(){
sort(L.begin(), L.end());
for (int i=0; i<N; i++){
if (vis[i]) continue;
int ind = L[i].i;
ans[ind] = ind;
vis[i] = 1;
for (int j=0; j<N; j++){
if (vis[j]) continue;
if (L[i].meet(L[j])){
ans[L[j].i] = ind;
vis[j] = 1;
}
}
}
}
void sub2(){
sort(L.begin(), L.end());
for (int i=0; i<N; i++){
S.insert(pii(L[i].x - L[i].r, i));
S.insert(pii(L[i].x + L[i].r, i));
}
set<pii>::iterator iter, temp;
for (int i=0; i<N; i++){
if (vis[i]) continue;
int ind = L[i].i;
ans[ind] = ind;
vis[i] = 1;
iter = S.lower_bound(make_pair(L[i].x-L[i].r, 0));
while ((iter != S.end())&&(!S.empty())){
temp = iter;
temp++;
if ((*iter).first <= L[i].x + L[i].r){
int j = (*iter).second;
if (!vis[j]){
ans[L[j].i] = ind;
vis[j] = 1;
}
}
S.erase(iter);
if ((temp == S.end()) || ((*temp).first > L[i].x + L[i].r)) break;
iter = temp;
}
}
}
int main(void){
int st = input();
if (st == 1){
sub1();
for (int i=0; i<N; i++){
printf("%d ", ans[i]+1);
}
printf("\n");
}
else if (st == 2){
sub2();
for (int i=0; i<N; i++) printf("%d ", ans[i] + 1);
printf("\n");
}
else{
printf("-1");
}
}
Compilation message
circle_selection.cpp: In function 'int input()':
circle_selection.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
circle_selection.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &x, &y, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
4 |
Correct |
3 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
3 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
3 ms |
580 KB |
Output is correct |
10 |
Correct |
2 ms |
580 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
580 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
620 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 |
4 ms |
620 KB |
Output is correct |
19 |
Correct |
6 ms |
880 KB |
Output is correct |
20 |
Correct |
7 ms |
1016 KB |
Output is correct |
21 |
Correct |
7 ms |
1016 KB |
Output is correct |
22 |
Correct |
82 ms |
1024 KB |
Output is correct |
23 |
Correct |
50 ms |
1024 KB |
Output is correct |
24 |
Correct |
53 ms |
1024 KB |
Output is correct |
25 |
Correct |
49 ms |
1024 KB |
Output is correct |
26 |
Correct |
58 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1259 ms |
37084 KB |
Output is correct |
2 |
Correct |
1233 ms |
37084 KB |
Output is correct |
3 |
Correct |
1128 ms |
43576 KB |
Output is correct |
4 |
Correct |
1170 ms |
50624 KB |
Output is correct |
5 |
Correct |
1146 ms |
54836 KB |
Output is correct |
6 |
Correct |
950 ms |
59676 KB |
Output is correct |
7 |
Correct |
1002 ms |
64512 KB |
Output is correct |
8 |
Correct |
1092 ms |
69312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
69312 KB |
Output is correct |
2 |
Incorrect |
57 ms |
69312 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
171 ms |
69312 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
4 |
Correct |
3 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
3 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
3 ms |
580 KB |
Output is correct |
10 |
Correct |
2 ms |
580 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
580 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
620 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 |
4 ms |
620 KB |
Output is correct |
19 |
Correct |
6 ms |
880 KB |
Output is correct |
20 |
Correct |
7 ms |
1016 KB |
Output is correct |
21 |
Correct |
7 ms |
1016 KB |
Output is correct |
22 |
Correct |
82 ms |
1024 KB |
Output is correct |
23 |
Correct |
50 ms |
1024 KB |
Output is correct |
24 |
Correct |
53 ms |
1024 KB |
Output is correct |
25 |
Correct |
49 ms |
1024 KB |
Output is correct |
26 |
Correct |
58 ms |
1024 KB |
Output is correct |
27 |
Incorrect |
8 ms |
69312 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
4 |
Correct |
3 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
3 ms |
580 KB |
Output is correct |
7 |
Correct |
2 ms |
580 KB |
Output is correct |
8 |
Correct |
3 ms |
580 KB |
Output is correct |
9 |
Correct |
3 ms |
580 KB |
Output is correct |
10 |
Correct |
2 ms |
580 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
580 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
3 ms |
620 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 |
4 ms |
620 KB |
Output is correct |
19 |
Correct |
6 ms |
880 KB |
Output is correct |
20 |
Correct |
7 ms |
1016 KB |
Output is correct |
21 |
Correct |
7 ms |
1016 KB |
Output is correct |
22 |
Correct |
82 ms |
1024 KB |
Output is correct |
23 |
Correct |
50 ms |
1024 KB |
Output is correct |
24 |
Correct |
53 ms |
1024 KB |
Output is correct |
25 |
Correct |
49 ms |
1024 KB |
Output is correct |
26 |
Correct |
58 ms |
1024 KB |
Output is correct |
27 |
Correct |
1259 ms |
37084 KB |
Output is correct |
28 |
Correct |
1233 ms |
37084 KB |
Output is correct |
29 |
Correct |
1128 ms |
43576 KB |
Output is correct |
30 |
Correct |
1170 ms |
50624 KB |
Output is correct |
31 |
Correct |
1146 ms |
54836 KB |
Output is correct |
32 |
Correct |
950 ms |
59676 KB |
Output is correct |
33 |
Correct |
1002 ms |
64512 KB |
Output is correct |
34 |
Correct |
1092 ms |
69312 KB |
Output is correct |
35 |
Correct |
2 ms |
69312 KB |
Output is correct |
36 |
Incorrect |
57 ms |
69312 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |