#pragma warning(disable:4996)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
vector<vector<ll>> circle;
vector<pair<ll, int>> sortRadius, sortX, sortY;
int ans[301000];
inline ll GetDist(ll x1, ll y1, ll x2, ll y2)
{
// 아 좌표값 마이너스도 들어오네
ll xx = max(x1, x2) - min(x1, x2);
ll yy = max(y1, y2) - min(y1, y2);
return xx * xx + yy * yy;
}
bool comp(const pair<ll,int>& a, const pair<ll,int>& b)
{
if (a.first == b.first)
return a.second < b.second;
return a.first < b.first;
}
bool compSort(const pair<ll, int>& a, const pair<ll, int>& b)
{
if (a.first == b.first)
{
return a.second < b.second;
}
return a.first > b.first;
}
int main()
{
ll x, y, r, r2;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld %lld %lld", &x, &y, &r);
// x = i + 1, y = i + 1, r = (i + 1)*3;
circle.push_back({ x,y,r });
sortRadius.push_back({ r,i });
sortX.push_back({ x,i });
sortY.push_back({ y,i });
}
sort(sortRadius.begin(), sortRadius.end(), compSort);
sort(sortX.begin(), sortX.end());
sort(sortY.begin(), sortY.end());
int cur, curcmp;
int xMin, xMax, yMin, yMax;
for (int curDelete = 0; curDelete < n; curDelete++)
{
if (ans[sortRadius[curDelete].second])
continue;
cur = sortRadius[curDelete].second;
x = circle[cur][0], y = circle[cur][1], r = circle[cur][2];
r2 = r * 2 + 2;
// a이하를 찾아야하는데 lower bound는 a이상인걸 찾으니까.. 근데 그 이하인걸 찾아야하니 1빼줌
xMin = lower_bound(sortX.begin(), sortX.end(), pair<ll, int>(x - r2, -1), comp) - sortX.begin() - 1;
xMax = upper_bound(sortX.begin(), sortX.end(), pair<ll, int>(x + r2, 301000), comp) - sortX.begin();
yMin = lower_bound(sortY.begin(), sortY.end(), pair<ll, int>(y - r2, -1), comp) - sortY.begin() - 1;
yMax = upper_bound(sortY.begin(), sortY.end(), pair<ll, int>(y + r2, 301000), comp) - sortY.begin();
if (xMin < 0) xMin = 0;
if (yMin < 0) yMin = 0;
if (xMin >= n) xMin = n - 1;
if (yMin >= n) yMin = n - 1;
if (xMax >= n) xMax = n - 1;
if (yMax >= n) yMax = n - 1;
ans[cur] = cur;
if (xMax - xMin < yMax - yMin)
{
for (int i = xMin; i <= xMax; i++)
{
curcmp = sortX[i].second;
if (ans[curcmp]) continue;
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (r + circle[curcmp][2]) * (r + circle[curcmp][2]))
ans[curcmp] = cur;
}
}
else
{
for (int i = yMin; i <= yMax; i++)
{
curcmp = sortY[i].second;
if (ans[curcmp]) continue;
if (GetDist(x, y, circle[curcmp][0], circle[curcmp][1]) <= (r + circle[curcmp][2]) * (r + circle[curcmp][2]))
ans[curcmp] = cur;
}
}
}
for (int i = 0; i < n; i++)
printf("%d ", ans[i]+1);
return 0;
}
Compilation message
circle_selection.cpp:1: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
1 | #pragma warning(disable:4996)
|
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | scanf("%lld %lld %lld", &x, &y, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
201 ms |
34436 KB |
Output is correct |
2 |
Correct |
215 ms |
34492 KB |
Output is correct |
3 |
Correct |
208 ms |
34172 KB |
Output is correct |
4 |
Correct |
208 ms |
34504 KB |
Output is correct |
5 |
Correct |
213 ms |
34292 KB |
Output is correct |
6 |
Correct |
285 ms |
34328 KB |
Output is correct |
7 |
Correct |
223 ms |
34348 KB |
Output is correct |
8 |
Correct |
223 ms |
34316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
216 ms |
11776 KB |
Output is correct |
3 |
Correct |
909 ms |
34320 KB |
Output is correct |
4 |
Correct |
882 ms |
34400 KB |
Output is correct |
5 |
Correct |
1113 ms |
33476 KB |
Output is correct |
6 |
Correct |
296 ms |
18252 KB |
Output is correct |
7 |
Correct |
107 ms |
9808 KB |
Output is correct |
8 |
Incorrect |
16 ms |
2696 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
604 ms |
34392 KB |
Output is correct |
2 |
Correct |
448 ms |
34304 KB |
Output is correct |
3 |
Incorrect |
898 ms |
33936 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
308 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |