Submission #1087259

# Submission time Handle Problem Language Result Execution time Memory
1087259 2024-09-12T11:40:06 Z TrungNotChung Circle selection (APIO18_circle_selection) C++11
100 / 100
1360 ms 49416 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;
        bool found = false;
        for (int i = 0; i < n; ++i) {
            if (res[circles[i].i] == -1 && circles[i].r >= r / 2 && circles[i].r <= r) {
                found = true;
                break;
            }
        }
        if(!found) continue;
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 2 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6180 KB Output is correct
5 Correct 3 ms 6232 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 6236 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 2 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 6184 KB Output is correct
15 Correct 2 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 4 ms 6560 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 11 ms 7008 KB Output is correct
23 Correct 12 ms 7004 KB Output is correct
24 Correct 12 ms 7004 KB Output is correct
25 Correct 11 ms 6820 KB Output is correct
26 Correct 11 ms 7012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 13928 KB Output is correct
2 Correct 120 ms 14692 KB Output is correct
3 Correct 118 ms 13872 KB Output is correct
4 Correct 117 ms 13872 KB Output is correct
5 Correct 168 ms 14256 KB Output is correct
6 Correct 468 ms 24952 KB Output is correct
7 Correct 185 ms 15280 KB Output is correct
8 Correct 246 ms 17744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 309 ms 20048 KB Output is correct
3 Correct 1159 ms 47348 KB Output is correct
4 Correct 1171 ms 47356 KB Output is correct
5 Correct 1226 ms 42020 KB Output is correct
6 Correct 422 ms 23892 KB Output is correct
7 Correct 169 ms 15696 KB Output is correct
8 Correct 25 ms 8280 KB Output is correct
9 Correct 1332 ms 46240 KB Output is correct
10 Correct 1018 ms 36608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1036 ms 45264 KB Output is correct
2 Correct 727 ms 46604 KB Output is correct
3 Correct 257 ms 24108 KB Output is correct
4 Correct 788 ms 48468 KB Output is correct
5 Correct 727 ms 48772 KB Output is correct
6 Correct 181 ms 19348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 2 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6180 KB Output is correct
5 Correct 3 ms 6232 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 6236 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 2 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 6184 KB Output is correct
15 Correct 2 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 4 ms 6560 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 11 ms 7008 KB Output is correct
23 Correct 12 ms 7004 KB Output is correct
24 Correct 12 ms 7004 KB Output is correct
25 Correct 11 ms 6820 KB Output is correct
26 Correct 11 ms 7012 KB Output is correct
27 Correct 6 ms 6748 KB Output is correct
28 Correct 6 ms 6588 KB Output is correct
29 Correct 6 ms 6740 KB Output is correct
30 Correct 23 ms 7684 KB Output is correct
31 Correct 23 ms 7516 KB Output is correct
32 Correct 26 ms 7676 KB Output is correct
33 Correct 43 ms 9680 KB Output is correct
34 Correct 39 ms 9804 KB Output is correct
35 Correct 44 ms 9540 KB Output is correct
36 Correct 285 ms 20036 KB Output is correct
37 Correct 318 ms 19188 KB Output is correct
38 Correct 306 ms 19384 KB Output is correct
39 Correct 238 ms 13832 KB Output is correct
40 Correct 237 ms 13736 KB Output is correct
41 Correct 242 ms 13740 KB Output is correct
42 Correct 155 ms 14416 KB Output is correct
43 Correct 189 ms 19048 KB Output is correct
44 Correct 198 ms 19016 KB Output is correct
45 Correct 198 ms 18960 KB Output is correct
46 Correct 185 ms 19024 KB Output is correct
47 Correct 202 ms 19084 KB Output is correct
48 Correct 192 ms 19700 KB Output is correct
49 Correct 187 ms 19796 KB Output is correct
50 Correct 202 ms 19728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 2 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6180 KB Output is correct
5 Correct 3 ms 6232 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 6236 KB Output is correct
9 Correct 3 ms 6236 KB Output is correct
10 Correct 2 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 6184 KB Output is correct
15 Correct 2 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 4 ms 6560 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 11 ms 7008 KB Output is correct
23 Correct 12 ms 7004 KB Output is correct
24 Correct 12 ms 7004 KB Output is correct
25 Correct 11 ms 6820 KB Output is correct
26 Correct 11 ms 7012 KB Output is correct
27 Correct 117 ms 13928 KB Output is correct
28 Correct 120 ms 14692 KB Output is correct
29 Correct 118 ms 13872 KB Output is correct
30 Correct 117 ms 13872 KB Output is correct
31 Correct 168 ms 14256 KB Output is correct
32 Correct 468 ms 24952 KB Output is correct
33 Correct 185 ms 15280 KB Output is correct
34 Correct 246 ms 17744 KB Output is correct
35 Correct 3 ms 6236 KB Output is correct
36 Correct 309 ms 20048 KB Output is correct
37 Correct 1159 ms 47348 KB Output is correct
38 Correct 1171 ms 47356 KB Output is correct
39 Correct 1226 ms 42020 KB Output is correct
40 Correct 422 ms 23892 KB Output is correct
41 Correct 169 ms 15696 KB Output is correct
42 Correct 25 ms 8280 KB Output is correct
43 Correct 1332 ms 46240 KB Output is correct
44 Correct 1018 ms 36608 KB Output is correct
45 Correct 1036 ms 45264 KB Output is correct
46 Correct 727 ms 46604 KB Output is correct
47 Correct 257 ms 24108 KB Output is correct
48 Correct 788 ms 48468 KB Output is correct
49 Correct 727 ms 48772 KB Output is correct
50 Correct 181 ms 19348 KB Output is correct
51 Correct 6 ms 6748 KB Output is correct
52 Correct 6 ms 6588 KB Output is correct
53 Correct 6 ms 6740 KB Output is correct
54 Correct 23 ms 7684 KB Output is correct
55 Correct 23 ms 7516 KB Output is correct
56 Correct 26 ms 7676 KB Output is correct
57 Correct 43 ms 9680 KB Output is correct
58 Correct 39 ms 9804 KB Output is correct
59 Correct 44 ms 9540 KB Output is correct
60 Correct 285 ms 20036 KB Output is correct
61 Correct 318 ms 19188 KB Output is correct
62 Correct 306 ms 19384 KB Output is correct
63 Correct 238 ms 13832 KB Output is correct
64 Correct 237 ms 13736 KB Output is correct
65 Correct 242 ms 13740 KB Output is correct
66 Correct 155 ms 14416 KB Output is correct
67 Correct 189 ms 19048 KB Output is correct
68 Correct 198 ms 19016 KB Output is correct
69 Correct 198 ms 18960 KB Output is correct
70 Correct 185 ms 19024 KB Output is correct
71 Correct 202 ms 19084 KB Output is correct
72 Correct 192 ms 19700 KB Output is correct
73 Correct 187 ms 19796 KB Output is correct
74 Correct 202 ms 19728 KB Output is correct
75 Correct 137 ms 17428 KB Output is correct
76 Correct 126 ms 17472 KB Output is correct
77 Correct 121 ms 17376 KB Output is correct
78 Correct 120 ms 17420 KB Output is correct
79 Correct 162 ms 17176 KB Output is correct
80 Correct 118 ms 17360 KB Output is correct
81 Correct 1312 ms 49020 KB Output is correct
82 Correct 1093 ms 48868 KB Output is correct
83 Correct 1160 ms 48800 KB Output is correct
84 Correct 1195 ms 49416 KB Output is correct
85 Correct 1138 ms 49048 KB Output is correct
86 Correct 1097 ms 48956 KB Output is correct
87 Correct 1352 ms 48720 KB Output is correct
88 Correct 898 ms 29992 KB Output is correct
89 Correct 873 ms 30056 KB Output is correct
90 Correct 884 ms 30076 KB Output is correct
91 Correct 893 ms 30080 KB Output is correct
92 Correct 877 ms 30252 KB Output is correct
93 Correct 1012 ms 47864 KB Output is correct
94 Correct 984 ms 48040 KB Output is correct
95 Correct 999 ms 47952 KB Output is correct
96 Correct 1115 ms 47940 KB Output is correct
97 Correct 1267 ms 47952 KB Output is correct
98 Correct 581 ms 31312 KB Output is correct
99 Correct 923 ms 48028 KB Output is correct
100 Correct 906 ms 47820 KB Output is correct
101 Correct 762 ms 36780 KB Output is correct
102 Correct 925 ms 47220 KB Output is correct
103 Correct 1360 ms 46704 KB Output is correct
104 Correct 921 ms 47752 KB Output is correct
105 Correct 604 ms 32852 KB Output is correct
106 Correct 681 ms 46512 KB Output is correct
107 Correct 700 ms 46672 KB Output is correct
108 Correct 697 ms 46540 KB Output is correct
109 Correct 701 ms 46596 KB Output is correct
110 Correct 687 ms 46616 KB Output is correct
111 Correct 706 ms 46600 KB Output is correct
112 Correct 682 ms 46524 KB Output is correct
113 Correct 682 ms 46676 KB Output is correct
114 Correct 663 ms 46484 KB Output is correct
115 Correct 659 ms 46676 KB Output is correct
116 Correct 640 ms 46672 KB Output is correct