Submission #1087251

# Submission time Handle Problem Language Result Execution time Memory
1087251 2024-09-12T11:29:21 Z TrungNotChung Circle selection (APIO18_circle_selection) C++11
49 / 100
3000 ms 347788 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) {
                    for(int c : grid[pii(x,y)]) {
                        if(res[circles[c].i] == -1 && intersect(circles[c], cur)) {
                            res[circles[c].i] = cur.i;
                        }
                    }
                }
            }
        }
    }

    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 3 ms 6236 KB Output is correct
2 Correct 2 ms 6308 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 6232 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6232 KB Output is correct
8 Correct 4 ms 6236 KB Output is correct
9 Correct 2 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 3 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 4 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6200 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6448 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6488 KB Output is correct
22 Correct 33 ms 10844 KB Output is correct
23 Correct 35 ms 11100 KB Output is correct
24 Correct 33 ms 9896 KB Output is correct
25 Correct 36 ms 10648 KB Output is correct
26 Correct 34 ms 10836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 16104 KB Output is correct
2 Correct 141 ms 17156 KB Output is correct
3 Correct 142 ms 16608 KB Output is correct
4 Correct 130 ms 15136 KB Output is correct
5 Correct 331 ms 16624 KB Output is correct
6 Correct 1229 ms 64664 KB Output is correct
7 Correct 385 ms 18816 KB Output is correct
8 Correct 556 ms 28956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 1092 ms 93732 KB Output is correct
3 Execution timed out 3048 ms 242856 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 347788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 2 ms 6308 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 6232 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6232 KB Output is correct
8 Correct 4 ms 6236 KB Output is correct
9 Correct 2 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 3 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 4 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6200 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6448 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6488 KB Output is correct
22 Correct 33 ms 10844 KB Output is correct
23 Correct 35 ms 11100 KB Output is correct
24 Correct 33 ms 9896 KB Output is correct
25 Correct 36 ms 10648 KB Output is correct
26 Correct 34 ms 10836 KB Output is correct
27 Correct 7 ms 6744 KB Output is correct
28 Correct 6 ms 6740 KB Output is correct
29 Correct 6 ms 6548 KB Output is correct
30 Correct 70 ms 16660 KB Output is correct
31 Correct 67 ms 16468 KB Output is correct
32 Correct 72 ms 14072 KB Output is correct
33 Correct 45 ms 10056 KB Output is correct
34 Correct 47 ms 10060 KB Output is correct
35 Correct 48 ms 10428 KB Output is correct
36 Correct 1141 ms 101532 KB Output is correct
37 Correct 1153 ms 90116 KB Output is correct
38 Correct 1072 ms 102972 KB Output is correct
39 Correct 279 ms 16056 KB Output is correct
40 Correct 280 ms 15852 KB Output is correct
41 Correct 279 ms 15972 KB Output is correct
42 Correct 195 ms 15152 KB Output is correct
43 Correct 926 ms 182476 KB Output is correct
44 Correct 919 ms 182748 KB Output is correct
45 Correct 938 ms 182444 KB Output is correct
46 Correct 922 ms 182580 KB Output is correct
47 Correct 953 ms 183144 KB Output is correct
48 Correct 960 ms 182916 KB Output is correct
49 Correct 964 ms 183108 KB Output is correct
50 Correct 928 ms 182540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6236 KB Output is correct
2 Correct 2 ms 6308 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 6232 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6232 KB Output is correct
8 Correct 4 ms 6236 KB Output is correct
9 Correct 2 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 3 ms 6236 KB Output is correct
14 Correct 3 ms 6236 KB Output is correct
15 Correct 4 ms 6236 KB Output is correct
16 Correct 3 ms 6236 KB Output is correct
17 Correct 3 ms 6200 KB Output is correct
18 Correct 3 ms 6236 KB Output is correct
19 Correct 6 ms 6448 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6488 KB Output is correct
22 Correct 33 ms 10844 KB Output is correct
23 Correct 35 ms 11100 KB Output is correct
24 Correct 33 ms 9896 KB Output is correct
25 Correct 36 ms 10648 KB Output is correct
26 Correct 34 ms 10836 KB Output is correct
27 Correct 143 ms 16104 KB Output is correct
28 Correct 141 ms 17156 KB Output is correct
29 Correct 142 ms 16608 KB Output is correct
30 Correct 130 ms 15136 KB Output is correct
31 Correct 331 ms 16624 KB Output is correct
32 Correct 1229 ms 64664 KB Output is correct
33 Correct 385 ms 18816 KB Output is correct
34 Correct 556 ms 28956 KB Output is correct
35 Correct 2 ms 6236 KB Output is correct
36 Correct 1092 ms 93732 KB Output is correct
37 Execution timed out 3048 ms 242856 KB Time limit exceeded
38 Halted 0 ms 0 KB -