Submission #474275

# Submission time Handle Problem Language Result Execution time Memory
474275 2021-09-17T18:25:11 Z khr03ae Circle selection (APIO18_circle_selection) C++14
0 / 100
174 ms 15256 KB
// 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");
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%d%d%d", &circles[i].x, &circles[i].y, &circles[i].radius);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 15256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 14944 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -