답안 #475176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475176 2021-09-21T10:39:36 Z khr03ae 원 고르기 (APIO18_circle_selection) C++14
7 / 100
31 ms 716 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long i64;

const int MAX = 5e3 + 9;

struct Circle {
    i64 x, y;
    i64 radius;
    i64 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) {
    i64 dx = a.x - b.x;
    i64 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("%lld%lld%lld", &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 = i + 1; 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("%lld%lld%lld", &circles[i].x, &circles[i].y, &circles[i].radius);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 5 ms 460 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 25 ms 468 KB Output is correct
23 Correct 25 ms 460 KB Output is correct
24 Correct 26 ms 472 KB Output is correct
25 Correct 24 ms 464 KB Output is correct
26 Correct 31 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 3 ms 716 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 5 ms 460 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 25 ms 468 KB Output is correct
23 Correct 25 ms 460 KB Output is correct
24 Correct 26 ms 472 KB Output is correct
25 Correct 24 ms 464 KB Output is correct
26 Correct 31 ms 472 KB Output is correct
27 Runtime error 3 ms 716 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 4 ms 460 KB Output is correct
20 Correct 5 ms 460 KB Output is correct
21 Correct 4 ms 460 KB Output is correct
22 Correct 25 ms 468 KB Output is correct
23 Correct 25 ms 460 KB Output is correct
24 Correct 26 ms 472 KB Output is correct
25 Correct 24 ms 464 KB Output is correct
26 Correct 31 ms 472 KB Output is correct
27 Runtime error 3 ms 716 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -