답안 #1087255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087255 2024-09-12T11:35:09 Z TrungNotChung 원 고르기 (APIO18_circle_selection) C++11
64 / 100
3000 ms 49456 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define task "main"

using namespace std;
const int N = (int)3e5 + 10; 

struct Circle {
    int x, y, r, i;
    Circle(int _x = 0, int _y = 0, int _r = 0, int _i = 0) {
        x = _x, y = _y, r = _r, i = _i;
    }
} circles[N];

int n;
int res[N];
 
bool cmp(const Circle &a, const Circle &b){
    if (a.r == b.r) return a.i < b.i;
    return a.r > b.r;
}

bool intersect(const Circle &a, const 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);
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> circles[i].x >> circles[i].y >> circles[i].r;
        circles[i].i = i;
    }
    sort (circles, circles + n, cmp);

    memset(res, -1, sizeof res);
    for (int lg = 30; lg >= 0; --lg) {
        int r = (1 << lg);
        map<pii, vector<int> > grid;
        for (int i = 0; i < n; ++i) {
            if (res[circles[i].i] == -1) {
                grid[pii(circles[i].x / r, circles[i].y / r)].push_back(i);
            }
        }
        for (int i = 0; i < n; ++i) {
            Circle &cur = circles[i];
            if (cur.r < r / 2) break;
            if (res[cur.i] != -1 || cur.r > r) continue;
            for(int x = cur.x / r - 2; x <= cur.x / r + 2; ++x) {
                for(int y = cur.y / r - 2; y <= cur.y / r + 2; ++y) {
                    if (grid.find(pii(x, y)) == grid.end()) continue;
                    vector<int> &candidates = grid[pii(x, y)];
                    for (int i = (int)candidates.size() - 1; i >= 0; --i) {
                        int c = candidates[i];
                        if (res[circles[c].i] == -1 && intersect(circles[c], cur)) {
                            res[circles[c].i] = cur.i;
                            swap (candidates[i], candidates.back());
                            candidates.pop_back();
                        }
                    }
                }
            }
        }
    }

    for(int i = 0; i < n; i++) cout << res[i] + 1 << ' ';
}
 
int main() {
#ifdef LOCAL
    freopen(task".inp", "r", stdin);
    freopen(task".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 3 ms 6236 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6296 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 3 ms 6236 KB Output is correct
11 Correct 3 ms 6236 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 3 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6236 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6492 KB Output is correct
20 Correct 5 ms 6488 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 21 ms 7024 KB Output is correct
23 Correct 21 ms 7004 KB Output is correct
24 Correct 26 ms 7020 KB Output is correct
25 Correct 23 ms 7004 KB Output is correct
26 Correct 21 ms 6952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 152 ms 12916 KB Output is correct
2 Correct 152 ms 17156 KB Output is correct
3 Correct 138 ms 16700 KB Output is correct
4 Correct 131 ms 15136 KB Output is correct
5 Correct 329 ms 15792 KB Output is correct
6 Correct 864 ms 25812 KB Output is correct
7 Correct 373 ms 16560 KB Output is correct
8 Correct 523 ms 18424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6232 KB Output is correct
2 Correct 525 ms 20648 KB Output is correct
3 Correct 2254 ms 49404 KB Output is correct
4 Correct 2383 ms 49456 KB Output is correct
5 Correct 1682 ms 43836 KB Output is correct
6 Correct 655 ms 24664 KB Output is correct
7 Correct 341 ms 15996 KB Output is correct
8 Correct 56 ms 8204 KB Output is correct
9 Correct 2096 ms 48144 KB Output is correct
10 Correct 1409 ms 41048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2609 ms 45588 KB Output is correct
2 Execution timed out 3006 ms 39432 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 3 ms 6236 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6296 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 3 ms 6236 KB Output is correct
11 Correct 3 ms 6236 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 3 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6236 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6492 KB Output is correct
20 Correct 5 ms 6488 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 21 ms 7024 KB Output is correct
23 Correct 21 ms 7004 KB Output is correct
24 Correct 26 ms 7020 KB Output is correct
25 Correct 23 ms 7004 KB Output is correct
26 Correct 21 ms 6952 KB Output is correct
27 Correct 6 ms 6748 KB Output is correct
28 Correct 6 ms 6748 KB Output is correct
29 Correct 7 ms 6748 KB Output is correct
30 Correct 42 ms 7712 KB Output is correct
31 Correct 39 ms 7516 KB Output is correct
32 Correct 43 ms 7732 KB Output is correct
33 Correct 47 ms 10024 KB Output is correct
34 Correct 46 ms 9988 KB Output is correct
35 Correct 49 ms 10360 KB Output is correct
36 Correct 581 ms 20468 KB Output is correct
37 Correct 593 ms 20540 KB Output is correct
38 Correct 557 ms 20428 KB Output is correct
39 Correct 302 ms 13956 KB Output is correct
40 Correct 300 ms 14004 KB Output is correct
41 Correct 304 ms 13976 KB Output is correct
42 Correct 218 ms 15052 KB Output is correct
43 Correct 484 ms 20224 KB Output is correct
44 Correct 485 ms 20128 KB Output is correct
45 Correct 488 ms 20096 KB Output is correct
46 Correct 503 ms 20080 KB Output is correct
47 Correct 487 ms 20272 KB Output is correct
48 Correct 488 ms 20088 KB Output is correct
49 Correct 478 ms 20108 KB Output is correct
50 Correct 489 ms 20284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 3 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 3 ms 6236 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6296 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 3 ms 6236 KB Output is correct
11 Correct 3 ms 6236 KB Output is correct
12 Correct 3 ms 6236 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 3 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6236 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6492 KB Output is correct
20 Correct 5 ms 6488 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 21 ms 7024 KB Output is correct
23 Correct 21 ms 7004 KB Output is correct
24 Correct 26 ms 7020 KB Output is correct
25 Correct 23 ms 7004 KB Output is correct
26 Correct 21 ms 6952 KB Output is correct
27 Correct 152 ms 12916 KB Output is correct
28 Correct 152 ms 17156 KB Output is correct
29 Correct 138 ms 16700 KB Output is correct
30 Correct 131 ms 15136 KB Output is correct
31 Correct 329 ms 15792 KB Output is correct
32 Correct 864 ms 25812 KB Output is correct
33 Correct 373 ms 16560 KB Output is correct
34 Correct 523 ms 18424 KB Output is correct
35 Correct 2 ms 6232 KB Output is correct
36 Correct 525 ms 20648 KB Output is correct
37 Correct 2254 ms 49404 KB Output is correct
38 Correct 2383 ms 49456 KB Output is correct
39 Correct 1682 ms 43836 KB Output is correct
40 Correct 655 ms 24664 KB Output is correct
41 Correct 341 ms 15996 KB Output is correct
42 Correct 56 ms 8204 KB Output is correct
43 Correct 2096 ms 48144 KB Output is correct
44 Correct 1409 ms 41048 KB Output is correct
45 Correct 2609 ms 45588 KB Output is correct
46 Execution timed out 3006 ms 39432 KB Time limit exceeded
47 Halted 0 ms 0 KB -