#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
struct C {
ll x, y, r, i;
};
const int N = 3e5 + 5, INF = 1e9;
map<pair<ll, ll>, vector<int>> mp;
bool used[N];
C cir[N];
int n;
int ans[N];
bool check(C a, C b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) <=
(a.r + b.r) * (a.r + b.r);
}
void build(int r) {
mp.clear();
for (int i = 0; i < n; i++) {
if (!used[i]) {
mp[{cir[i].x / r, cir[i].y / r}].push_back(i);
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
int cur = 0;
for (int i = 0; i < n; i++) {
cin >> cir[i].x >> cir[i].y >> cir[i].r;
cir[i].x += INF;
cir[i].y += INF;
cir[i].i = i;
}
sort(cir, cir + n, [](const C &a, const C &b) {
return a.r > b.r;
});
cur = cir[0].r;
build(cur);
for (int i = 0; i < n; i++) {
if (!used[i]) {
// cout << cir[i].x << " " << cir[i].y << " " << cir[i].r << "\n";
if (cir[i].r * 2 < cur) {
cur = cir[i].r;
build(cur);
}
int x = cir[i].x / cur,
y = cir[i].y / cur;
for (int j = x - 5; j <= x + 5; j++) {
for (int k = y - 5; k <= y + 5; k++) {
if (mp.count({j, k})) {
vector<int> &v = mp[{j, k}];
for (int h = 0; h < v.size(); h++) {
if (check(cir[i], cir[v[h]])) {
ans[cir[v[h]].i] = cir[i].i;
used[v[h]] = 1;
swap(v.back(), v[h]);
v.pop_back();
h--;
}
}
}
}
}
}
}
for (int i = 0; i < n; i++) {
cout << ans[i] + 1 << " ";
}
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:72:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int h = 0; h < v.size(); h++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
30 ms |
1272 KB |
Output is correct |
23 |
Correct |
35 ms |
1272 KB |
Output is correct |
24 |
Correct |
29 ms |
1240 KB |
Output is correct |
25 |
Correct |
26 ms |
1272 KB |
Output is correct |
26 |
Correct |
29 ms |
1164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
13832 KB |
Output is correct |
2 |
Correct |
211 ms |
14052 KB |
Output is correct |
3 |
Correct |
203 ms |
14824 KB |
Output is correct |
4 |
Correct |
207 ms |
14120 KB |
Output is correct |
5 |
Incorrect |
281 ms |
14504 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
1128 ms |
15892 KB |
Output is correct |
3 |
Execution timed out |
3052 ms |
44520 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3049 ms |
44408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
30 ms |
1272 KB |
Output is correct |
23 |
Correct |
35 ms |
1272 KB |
Output is correct |
24 |
Correct |
29 ms |
1240 KB |
Output is correct |
25 |
Correct |
26 ms |
1272 KB |
Output is correct |
26 |
Correct |
29 ms |
1164 KB |
Output is correct |
27 |
Correct |
9 ms |
1144 KB |
Output is correct |
28 |
Correct |
9 ms |
1144 KB |
Output is correct |
29 |
Correct |
9 ms |
1144 KB |
Output is correct |
30 |
Correct |
70 ms |
2040 KB |
Output is correct |
31 |
Correct |
66 ms |
2112 KB |
Output is correct |
32 |
Correct |
64 ms |
2168 KB |
Output is correct |
33 |
Correct |
73 ms |
5508 KB |
Output is correct |
34 |
Correct |
72 ms |
5620 KB |
Output is correct |
35 |
Correct |
76 ms |
5072 KB |
Output is correct |
36 |
Correct |
915 ms |
16004 KB |
Output is correct |
37 |
Correct |
907 ms |
16092 KB |
Output is correct |
38 |
Correct |
985 ms |
15940 KB |
Output is correct |
39 |
Incorrect |
930 ms |
14232 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
5 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 |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
380 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
6 ms |
760 KB |
Output is correct |
22 |
Correct |
30 ms |
1272 KB |
Output is correct |
23 |
Correct |
35 ms |
1272 KB |
Output is correct |
24 |
Correct |
29 ms |
1240 KB |
Output is correct |
25 |
Correct |
26 ms |
1272 KB |
Output is correct |
26 |
Correct |
29 ms |
1164 KB |
Output is correct |
27 |
Correct |
199 ms |
13832 KB |
Output is correct |
28 |
Correct |
211 ms |
14052 KB |
Output is correct |
29 |
Correct |
203 ms |
14824 KB |
Output is correct |
30 |
Correct |
207 ms |
14120 KB |
Output is correct |
31 |
Incorrect |
281 ms |
14504 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |