#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int INF = 2e9;
struct circle {
int x, y, r;
};
bool inter(circle a, 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);
}
map <pair<int, int>, vector <int> > mapa;
int n;
circle t[300005];
int cur = INF;
vector <int> v;
int ans[300005];
void go() {
mapa.clear();
for(int i = 1; i <= n; ++i) {
if(ans[i]) continue;
mapa[mp(t[i].x / cur, t[i].y / cur)].pb(i);
}
}
vector <int> wywal;
void solve(int x, int y, int id) {
for(int i = 0; i < ss(mapa[mp(x, y)]); ++i) {
auto it = mapa[mp(x, y)][i];
if(ans[it]) continue;
if(inter(t[id], t[it])) {
ans[it] = id;
wywal.pb(i);
}
}
for(int i = ss(wywal) - 1; 0 <= i; --i) {
int it = wywal[i];
swap(mapa[mp(x, y)][it], mapa[mp(x, y)].back());
mapa[mp(x, y)].pop_back();
}
wywal.clear();
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d %d %d", &t[i].x, &t[i].y, &t[i].r);
t[i].x += 1000000000;
t[i].y += 1000000000;
v.pb(i);
}
sort(v.begin(), v.end(), [](int a, int b) {
if(t[a].r != t[b].r)
return t[a].r < t[b].r;
return a > b;
});
go();
for(int i = n - 1; 0 <= i; --i) {
int ja = v[i];
if(!ans[ja]) {
if(2 * t[ja].r < cur) {
cur = t[ja].r;
go();
}
for(int x = t[ja].x / cur - 2; x <= t[ja].x / cur + 2; ++x)
for(int y = t[ja].y / cur - 2; y <= t[ja].y / cur + 2; ++y)
solve(x, y, ja);
}
}
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:59:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
circle_selection.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &t[i].x, &t[i].y, &t[i].r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
424 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
764 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
50 ms |
5880 KB |
Output is correct |
23 |
Correct |
52 ms |
5856 KB |
Output is correct |
24 |
Correct |
50 ms |
5880 KB |
Output is correct |
25 |
Correct |
47 ms |
5936 KB |
Output is correct |
26 |
Correct |
49 ms |
6012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
12744 KB |
Output is correct |
2 |
Correct |
247 ms |
17608 KB |
Output is correct |
3 |
Correct |
238 ms |
17352 KB |
Output is correct |
4 |
Correct |
240 ms |
18448 KB |
Output is correct |
5 |
Correct |
359 ms |
17532 KB |
Output is correct |
6 |
Correct |
1694 ms |
87032 KB |
Output is correct |
7 |
Correct |
476 ms |
22192 KB |
Output is correct |
8 |
Correct |
736 ms |
32712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1811 ms |
107852 KB |
Output is correct |
3 |
Execution timed out |
3041 ms |
326492 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3073 ms |
406888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
424 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
764 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
50 ms |
5880 KB |
Output is correct |
23 |
Correct |
52 ms |
5856 KB |
Output is correct |
24 |
Correct |
50 ms |
5880 KB |
Output is correct |
25 |
Correct |
47 ms |
5936 KB |
Output is correct |
26 |
Correct |
49 ms |
6012 KB |
Output is correct |
27 |
Correct |
10 ms |
1016 KB |
Output is correct |
28 |
Correct |
10 ms |
1012 KB |
Output is correct |
29 |
Correct |
10 ms |
1016 KB |
Output is correct |
30 |
Correct |
121 ms |
11324 KB |
Output is correct |
31 |
Correct |
108 ms |
11320 KB |
Output is correct |
32 |
Correct |
107 ms |
11380 KB |
Output is correct |
33 |
Correct |
86 ms |
7500 KB |
Output is correct |
34 |
Correct |
86 ms |
7064 KB |
Output is correct |
35 |
Correct |
92 ms |
6592 KB |
Output is correct |
36 |
Correct |
1690 ms |
110880 KB |
Output is correct |
37 |
Correct |
1658 ms |
110492 KB |
Output is correct |
38 |
Correct |
1742 ms |
110368 KB |
Output is correct |
39 |
Correct |
784 ms |
31372 KB |
Output is correct |
40 |
Correct |
773 ms |
31500 KB |
Output is correct |
41 |
Correct |
763 ms |
31352 KB |
Output is correct |
42 |
Correct |
378 ms |
15848 KB |
Output is correct |
43 |
Correct |
1195 ms |
178916 KB |
Output is correct |
44 |
Correct |
1241 ms |
179300 KB |
Output is correct |
45 |
Correct |
1179 ms |
178964 KB |
Output is correct |
46 |
Correct |
1184 ms |
179192 KB |
Output is correct |
47 |
Correct |
1192 ms |
179508 KB |
Output is correct |
48 |
Correct |
1182 ms |
179384 KB |
Output is correct |
49 |
Correct |
1242 ms |
179488 KB |
Output is correct |
50 |
Correct |
1197 ms |
179060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
424 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
3 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
764 KB |
Output is correct |
20 |
Correct |
6 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
632 KB |
Output is correct |
22 |
Correct |
50 ms |
5880 KB |
Output is correct |
23 |
Correct |
52 ms |
5856 KB |
Output is correct |
24 |
Correct |
50 ms |
5880 KB |
Output is correct |
25 |
Correct |
47 ms |
5936 KB |
Output is correct |
26 |
Correct |
49 ms |
6012 KB |
Output is correct |
27 |
Correct |
239 ms |
12744 KB |
Output is correct |
28 |
Correct |
247 ms |
17608 KB |
Output is correct |
29 |
Correct |
238 ms |
17352 KB |
Output is correct |
30 |
Correct |
240 ms |
18448 KB |
Output is correct |
31 |
Correct |
359 ms |
17532 KB |
Output is correct |
32 |
Correct |
1694 ms |
87032 KB |
Output is correct |
33 |
Correct |
476 ms |
22192 KB |
Output is correct |
34 |
Correct |
736 ms |
32712 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
1811 ms |
107852 KB |
Output is correct |
37 |
Execution timed out |
3041 ms |
326492 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |