#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
struct circle{
int x, y, r, id;
bool operator<(const circle& a)const{
return x < a.x || (x == a.x && id < a.id);
}
};
int dist(circle& a, circle& b){
int x = a.x - b.x;
int y = a.y - b.y;
return x * x + y * y;
}
bool isect(circle& a, circle& b){
return dist(a, b) <= (a.r + b.r) * (a.r + b.r);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<circle> X;
vector<circle> data;
vector<int> seq;
int n;
cin >> n;
vector<int> ans(n, -1);
for(int i = 0; i < n; i++){
int x, y, r;
cin >> x >> y >> r; swap(x, y);
X.pb({x, y, r, i});
data.pb({x, y, r, i});
}
sort(all(data), [&](circle a, circle b){return a.r > b.r || (a.r == b.r && a.id < b.id);});
for(int i = 0; i < n; i++) seq.pb(i);
sort(all(seq), [&](int x, int y){return X[x].x < X[y].x;});
vector<int> ptr(n);
for(int i = 0; i < n; i++) ptr[seq[i]] = i;
for(auto c : data){
if(ans[c.id] >= 0) continue;
for(int j = ptr[c.id] + 1; j < n && ans[seq[j]] == -1 && isect(X[c.id], X[seq[j]]); j++){
ans[seq[j]] = c.id;
}
for(int j = ptr[c.id] - 1; j >= 0 && ans[seq[j]] == -1 && isect(X[c.id], X[seq[j]]); j--){
ans[seq[j]] = c.id;
}
ans[c.id] = c.id;
}
for(int i = 0; i < n; i++){
cout << ans[i] + 1 << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
217 ms |
30088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
92 ms |
10192 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
251 ms |
29956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |