bool home = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int) 3e5 + 7;
const int INF = (int) 1e9 + 7;
int n;
struct Circle {
int x;
int y;
int r;
};
bool doIntersect(Circle a, Circle b) {
/// dist <= a.r + b.r
/// dist ^ 2 <= (a.r + b.r) ^ 2
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);
}
Circle circles[N];
int ret[N];
map<pair<int, int>, set<int>> guysAtPosition;
bool cmp(int i, int j) {
if (circles[i].r == circles[j].r) {
return i < j;
} else {
return circles[i].r > circles[j].r;
}
}
set<int, decltype(cmp)*> s(cmp);
int r_divide_glob;
void place(int r_divide, set<int, decltype(cmp)*>& s) {
r_divide_glob = r_divide;
guysAtPosition.clear();
for (auto &i : s) {
guysAtPosition[{circles[i].x / r_divide, circles[i].y / r_divide}].insert(i);
}
}
void elim(int i, set<int, decltype(cmp)*>& s) {
int x = circles[i].x / r_divide_glob, y = circles[i].y / r_divide_glob;
for (int x2 = x - 2; x2 <= x + 2; x2++) {
for (int y2 = y - 2; y2 <= y + 2; y2++) {
pair<int, int> it = {x2, y2};
vector<int> dl;
for (auto &j : guysAtPosition[it]) {
if (doIntersect(circles[i], circles[j])) {
ret[j] = i;
s.erase(j);
dl.push_back(j);
}
}
for (auto &j : dl) {
guysAtPosition[it].erase(j);
}
}
}
}
int main() {
if (home == 0) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
} else {
freopen ("input.txt", "r", stdin);
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
circles[i].x += INF;
circles[i].y += INF;
}
for (int i = 1; i <= n; i++) {
s.insert(i);
}
int max_radius = circles[1].r;
for (int i = 2; i <= n; i++) {
max_radius = max(max_radius, circles[i].r);
}
place(max_radius, s);
while (!s.empty()) {
int i = *s.begin();
elim(i, s);
}
for (int i = 1; i <= n; i++) {
cout << ret[i] << " ";
}
cout << "\n";
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:75:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen ("input.txt", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
1056 KB |
Output is correct |
20 |
Correct |
6 ms |
980 KB |
Output is correct |
21 |
Correct |
6 ms |
980 KB |
Output is correct |
22 |
Correct |
49 ms |
12492 KB |
Output is correct |
23 |
Correct |
41 ms |
12504 KB |
Output is correct |
24 |
Correct |
38 ms |
12456 KB |
Output is correct |
25 |
Correct |
36 ms |
12492 KB |
Output is correct |
26 |
Correct |
38 ms |
12552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
897 ms |
36184 KB |
Output is correct |
2 |
Correct |
944 ms |
42336 KB |
Output is correct |
3 |
Correct |
899 ms |
41828 KB |
Output is correct |
4 |
Correct |
827 ms |
42320 KB |
Output is correct |
5 |
Correct |
846 ms |
40492 KB |
Output is correct |
6 |
Correct |
1521 ms |
106980 KB |
Output is correct |
7 |
Correct |
960 ms |
42104 KB |
Output is correct |
8 |
Correct |
1077 ms |
47688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1279 ms |
237780 KB |
Output is correct |
3 |
Execution timed out |
3064 ms |
596780 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3102 ms |
696192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
1056 KB |
Output is correct |
20 |
Correct |
6 ms |
980 KB |
Output is correct |
21 |
Correct |
6 ms |
980 KB |
Output is correct |
22 |
Correct |
49 ms |
12492 KB |
Output is correct |
23 |
Correct |
41 ms |
12504 KB |
Output is correct |
24 |
Correct |
38 ms |
12456 KB |
Output is correct |
25 |
Correct |
36 ms |
12492 KB |
Output is correct |
26 |
Correct |
38 ms |
12552 KB |
Output is correct |
27 |
Correct |
12 ms |
1748 KB |
Output is correct |
28 |
Correct |
12 ms |
1840 KB |
Output is correct |
29 |
Correct |
12 ms |
1784 KB |
Output is correct |
30 |
Correct |
94 ms |
24704 KB |
Output is correct |
31 |
Correct |
89 ms |
24656 KB |
Output is correct |
32 |
Correct |
91 ms |
24908 KB |
Output is correct |
33 |
Correct |
173 ms |
15092 KB |
Output is correct |
34 |
Correct |
200 ms |
15064 KB |
Output is correct |
35 |
Correct |
203 ms |
14872 KB |
Output is correct |
36 |
Correct |
1137 ms |
244888 KB |
Output is correct |
37 |
Correct |
1141 ms |
245108 KB |
Output is correct |
38 |
Correct |
1162 ms |
244540 KB |
Output is correct |
39 |
Execution timed out |
3068 ms |
12364 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
224 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
6 ms |
1056 KB |
Output is correct |
20 |
Correct |
6 ms |
980 KB |
Output is correct |
21 |
Correct |
6 ms |
980 KB |
Output is correct |
22 |
Correct |
49 ms |
12492 KB |
Output is correct |
23 |
Correct |
41 ms |
12504 KB |
Output is correct |
24 |
Correct |
38 ms |
12456 KB |
Output is correct |
25 |
Correct |
36 ms |
12492 KB |
Output is correct |
26 |
Correct |
38 ms |
12552 KB |
Output is correct |
27 |
Correct |
897 ms |
36184 KB |
Output is correct |
28 |
Correct |
944 ms |
42336 KB |
Output is correct |
29 |
Correct |
899 ms |
41828 KB |
Output is correct |
30 |
Correct |
827 ms |
42320 KB |
Output is correct |
31 |
Correct |
846 ms |
40492 KB |
Output is correct |
32 |
Correct |
1521 ms |
106980 KB |
Output is correct |
33 |
Correct |
960 ms |
42104 KB |
Output is correct |
34 |
Correct |
1077 ms |
47688 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1279 ms |
237780 KB |
Output is correct |
37 |
Execution timed out |
3064 ms |
596780 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |