# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
169769 | ZwariowanyMarcin | 원 고르기 (APIO18_circle_selection) | C++14 | 3051 ms | 351016 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)
using namespace std;
const int INF = 2e9;
struct circle {
int x, y, r;
};
bool inter(circle a, circle 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);
}
map <pair<int, int>, vector <int> > mapa;
int n;
circle t[300005];
int cur = INF;
vector <int> v;
int ans[300005];
void go() {
mapa.clear();
for(int i = 1; i <= n; ++i) {
if(ans[i]) continue;
mapa[mp(t[i].x / cur, t[i].y / cur)].pb(i);
}
}
vector <int> wywal;
void solve(int x, int y, int id) {
for(int i = 0; i < ss(mapa[mp(x, y)]); ++i) {
auto it = mapa[mp(x, y)][i];
if(ans[it]) continue;
if(inter(t[id], t[it])) {
ans[it] = id;
}
else {
wywal.pb(it);
}
}
mapa[mp(x, y)] = wywal;
wywal.clear();
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d %d %d", &t[i].x, &t[i].y, &t[i].r);
t[i].x += 1000000000;
t[i].y += 1000000000;
v.pb(i);
}
sort(v.begin(), v.end(), [](int a, int b) {
if(t[a].r != t[b].r)
return t[a].r < t[b].r;
return a > b;
});
go();
for(int i = n - 1; 0 <= i; --i) {
int ja = v[i];
if(!ans[ja]) {
if(2 * t[ja].r < cur) {
cur = t[ja].r;
go();
}
for(int x = t[ja].x / cur - 2; x <= t[ja].x / cur + 2; ++x)
for(int y = t[ja].y / cur - 2; y <= t[ja].y / cur + 2; ++y)
solve(x, y, ja);
}
}
for(int i = 1; i <= n; ++i)
printf("%d ", ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |