이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
using namespace std;
struct cir
{
int x, y, r, i;
bool operator <(const cir &a) const
{
return r != a.r ? r > a.r : i < a.i;
}
};
const int MAXN = 300000;
const int MAXV = 1000000000;
cir arr[MAXN + 10];
int num[MAXN + 10];
int res[MAXN + 10];
int n;
bool inter(const cir &a, const cir &b)
{
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);
}
vector<long long> com;
long long tmp[MAXN + 10];
vector<int> lis[MAXN + 10];
inline int idx(long long x)
{
return lower_bound(com.begin(), com.end(), x) - com.begin();
}
inline long long idx2(int x, int y, int r)
{
return (2LL * MAXV + 1) * ((x + MAXV) / r) + (y + MAXV) / r;
}
void init(int s, int mx)
{
com.clear();
for(int i = 0; i < n - s; i++)
lis[i].clear();
for(int i = s; i <= n; i++)
{
if(num[i])
continue;
tmp[i] = idx2(arr[i].x, arr[i].y, mx);
com.push_back(tmp[i]);
}
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
for(int i = s; i <= n; i++)
{
if(num[i])
continue;
lis[idx(tmp[i])].push_back(i);
}
}
int main()
{
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
int i, j, k;
scanf("%d", &n);
for(i = 1; i <= n; i++)
{
int x, y, r;
scanf("%d%d%d", &x, &y, &r);
arr[i] = { x, y, r, i };
}
sort(arr + 1, arr + n + 1);
int mx = arr[1].r;
init(1, mx);
for(i = 1; i <= n; i++)
{
if(num[i])
continue;
if(arr[i].r <= mx / 2)
{
mx = arr[i].r;
init(i, mx);
}
for(j = -2; j <= 2; j++)
{
for(k = -2; k <= 2; k++)
{
int nx = max(0LL + -MAXV, min(0LL + MAXV, arr[i].x + 1LL * j * mx));
int ny = max(0LL + -MAXV, min(0LL + MAXV, arr[i].y + 1LL * k * mx));
long long t = idx2(nx, ny, mx);
int t2 = idx(t);
if(t2 == com.size() || com[t2] != t)
continue;
vector<int> nex;
for(int &x : lis[t2])
{
if(inter(arr[i], arr[x]))
num[x] = arr[i].i;
else
nex.push_back(x);
}
lis[t2] = nex;
}
}
}
for(i = 1; i <= n; i++)
res[arr[i].i] = num[i];
for(i = 1; i <= n; i++)
printf("%d ", res[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:119:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(t2 == com.size() || com[t2] != t)
~~~^~~~~~~~~~~~~
circle_selection.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
circle_selection.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &x, &y, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |