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>
#include <array>
#define all(v) (v.begin()), (v.end())
#define setall(a, val) for(auto& x : a) x = val
#define ll long long
clock_t start_time;
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
void init() {
#ifndef ONLINE_JUDGE
FILE* _ = freopen("in.txt", "r", stdin);
start_time = clock();
#endif
}
const ll MOD = 998244353;
const ll N = 6e5 + 1;
const ll M = 2e2 + 1;
using namespace std;
//####################################################################################
bool comp(array<ll, 4> a, array<ll, 4> b) {
if (a[0] == b[0])
return a[3] < b[3];
return a[0] > b[0];
}
bool comp2(array<ll, 4> a, array<ll, 4> b) {
return a[1] < b[1];
}
double dist(ll x1, ll y1, ll x2, ll y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); //init();
int n;
cin >> n;
vector< array<ll, 4> > v(n); // {radius, x, y, idx}
for (int i = 0; i < n; i++)
cin >> v[i][1] >> v[i][2] >> v[i][0], v[i][3] = i + 1;
sort(all(v), comp);
map<int, int> m;
vector< array<ll, 4> > s = v;
sort(all(s), comp2);
for (int i = 0; i < n; i++)
m[s[i][3]] = i;
vector<int> ans(n + 1, 0);
for (int i = 0; i < n; i++) {
if (ans[v[i][3]])
continue;
ans[v[i][3]] = v[i][3];
if (n <= 5000) {
for (int j = i + 1; j < n; j++) {
if (!ans[v[j][3]] && dist(v[i][1], v[i][2], v[j][1], v[j][2]) <= v[i][0] + v[j][0])
ans[v[j][3]] = v[i][3];
}
}
else {
for (int j = m[v[i][3]] + 1; j < n; j++) {
if (ans[s[j][3]] || s[j][1] - v[i][1] > v[i][0] + s[j][0])
continue;
ans[s[j][3]] = v[i][3];
}
for (int j = m[v[i][3]] - 1; j >= 0; j--) {
if (ans[s[j][3]] || v[i][1] - s[j][1] > v[i][0] + s[j][0])
continue;
ans[s[j][3]] = v[i][3];
}
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout << endl;
//cerr << get_time() << "s" << endl;
}
Compilation message (stderr)
circle_selection.cpp: In function 'void init()':
circle_selection.cpp:10:8: warning: unused variable '_' [-Wunused-variable]
10 | FILE* _ = freopen("in.txt", "r", stdin);
| ^
# | 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... |