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>, vector<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}].push_back(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};
if (!guysAtPosition.count(it)) {
continue;
}
for (auto &j : guysAtPosition[it]) {
if (doIntersect(circles[i], circles[j])) {
ret[j] = i;
s.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();
if (circles[i].r <= max_radius / 2) {
max_radius = circles[i].r;
place(max_radius, s);
}
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:74:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen ("input.txt", "r", stdin);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
449 ms |
21384 KB |
Output is correct |
2 |
Incorrect |
487 ms |
21428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
499 ms |
18164 KB |
Output is correct |
3 |
Correct |
2003 ms |
54064 KB |
Output is correct |
4 |
Correct |
2050 ms |
54468 KB |
Output is correct |
5 |
Correct |
2116 ms |
47780 KB |
Output is correct |
6 |
Correct |
774 ms |
24148 KB |
Output is correct |
7 |
Correct |
300 ms |
13312 KB |
Output is correct |
8 |
Correct |
36 ms |
3420 KB |
Output is correct |
9 |
Correct |
2415 ms |
53528 KB |
Output is correct |
10 |
Correct |
2025 ms |
46340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1519 ms |
54184 KB |
Output is correct |
2 |
Correct |
1102 ms |
54400 KB |
Output is correct |
3 |
Incorrect |
878 ms |
31540 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |