This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct circle {
int x, y, r;
};
int n;
vector<pair<circle, int>> v;
const bool operator>(const pair<circle, int> &lhs, const pair<circle, int> &rhs) {
if (lhs.first.r != rhs.first.r) return lhs.first.r > rhs.first.r;
return lhs.second < rhs.second;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
//priority_queue<pair<circle, int>> pq;
for (int i = 0; i < n; i++) {
int x, y, r;
cin >> x >> y >> r;
//pq.push({{x, y, r}, i});
v.push_back({{x, y, r}, i});
}
sort(v.begin(), v.end(), [](const pair<circle, int>& a, const pair<circle, int>& b) {
if (a.first.r != b.first.r) return a.first.r > b.first.r;
return a.second < b.second;
});
#ifdef DEBUG
//for (auto& c : v) {
// cout << c.first.x << ' ' << c.first.y << ' ' << c.first.r << ' ' << c.second << '\n';
//}
#endif
int idx = 0;
bitset<5005> used;
vector<int> ans(n);
while (idx < n) {
if (used[idx]) {
idx++;
continue;
}
used[idx] = true;
ans[v[idx].second] = v[idx].second;
for (int i = 0; i < n; i++) {
if (i == idx) continue;
if (hypot(double(v[i].first.x - v[idx].first.x), double(v[i].first.y - v[idx].first.y)) <= double(v[i].first.r + v[idx].first.r)) {
used[i] = true;
ans[v[i].second] = v[idx].second;
}
}
idx++;
}
/*bitset<5005> used;
vector<int> ans(n);
while (!pq.empty()) {
auto cur = pq.top(); pq.pop();
}*/
for (int i = 0; i < n; i++) {
if (i) cout << ' ';
cout << ans[i] + 1;
}
cout << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |