Submission #475174

# Submission time Handle Problem Language Result Execution time Memory
475174 2021-09-21T10:36:45 Z khr03ae Circle selection (APIO18_circle_selection) C++14
0 / 100
3 ms 460 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

const int MAX = 5e3 + 9;

struct Circle {
    int x, y;
    int radius;
    int index;
} circles[MAX];

int N, par[MAX];
bool deleted[MAX];

void init() {
    for (int i = 0; i < N; ++i) {
        par[i] = i;
        deleted[i] = false;
    }
}

bool cmp(Circle& a, Circle &b) {
    if (a.radius == b.radius)
        return a.index < b.index;
    return a.radius > b.radius;
}

bool intercept(Circle& a, Circle& b) {
    int dx = a.x - b.x;
    int dy = a.y - b.y;
    i64 dist2 = dx * dx * 1LL + dy * dy * 1LL;
    i64 r2 = (a.radius * 1LL + b.radius * 1LL) * (a.radius * 1LL + b.radius * 1LL) * 1LL;
    if (dist2 <= r2) {
        return true;
    }  else {
        return false;
    }
}

int main() {
    scanf("%d", &N);
    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, cmp);
    init();
    // for (int i = 0; i < N; ++i) {
    //     printf("%d %d %d %d\n", circles[i].x, circles[i].y, circles[i].radius, circles[i].index);
    // }
    for (int i = 0; i < N; ++i) {
        int u = circles[i].index;
        if (deleted[u])
            continue;
        for (int j = 0; j < N; ++j) {
            int v = circles[j].index;
            if (intercept(circles[i], circles[j]) && !deleted[v]) {
                par[v] = u;
                deleted[v] = true;
            }
        }
        deleted[u] = 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:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d%d%d", &circles[i].x, &circles[i].y, &circles[i].radius);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 460 KB Execution killed with signal 11
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 Runtime error 3 ms 460 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -