# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
474275 | khr03ae | 원 고르기 (APIO18_circle_selection) | C++14 | 174 ms | 15256 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// APIO 2018
// Problem 2 Subtask 1
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 3 * (1e5 + 9);
struct Circle {
int x, y;
int radius;
int index;
bool operator < (const Circle& rhs) {
if (radius == rhs.radius) {
return index < rhs.index;
} else {
return radius > rhs.radius;
}
}
} circles[MAX];
bool erase[MAX];
int par[MAX];
bool intercept(Circle &c1, Circle &c2) {
int dx = c1.x - c2.x;
int dy = c1.y - c2.y;
i64 dist = dx * dx * 1LL + dy * dy * 1LL; // 두 원의 중심 사이의 거리 ^ 2
i64 r = (c1.radius * 1LL + c2.radius * 1LL) * (c1.radius * 1LL + c2.radius * 1LL); // 두 원의 반지름의 합 ^ 2
if (dist <= r) {
return true;
} else {
return false;
}
}
int main() {
int N;
scanf("%d", &N);
fill(erase, erase + N, false);
for (int i = 0; i < N; ++i) {
scanf("%d%d%d", &circles[i].x, &circles[i].y, &circles[i].radius);
circles[i].index = i;
}
sort(circles, circles + N);
// 에라스토테네스의 체 같은 느낌으로?
for (int i = 0; i < N; ++i) {
if (!erase[circles[i].index]) {
printf("%d\n", circles[i].index + 1);
// 제거되지 않았다면 교차되는 원을 찾는다.
for (int j = i + 1; j < N; ++j) {
if (!erase[circles[j].index] && intercept(circles[i], circles[j])) {
par[circles[j].index] = circles[i].index;
erase[circles[j].index] = true;
}
}
par[circles[i].index] = circles[i].index;
erase[circles[i].index] = true;
}
}
for (int i = 0; i < N; ++i) {
printf("%d ", par[i] + 1);
}
printf("\n");
}
컴파일 시 표준 에러 (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... |