Submission #1105430

# Submission time Handle Problem Language Result Execution time Memory
1105430 2024-10-26T11:36:36 Z sqwiijqk Circle selection (APIO18_circle_selection) C++17
100 / 100
1642 ms 49480 KB
#include <bits/stdc++.h>

using namespace std;

void solve();

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int qwerty = 1;
    // cin >> qwerty;
    while (qwerty--) {
        solve();
    }
}

struct circle {
    int x, y, r, ind;
};

bool cmp(circle a, circle b) {
    return a.r > b.r || (a.r == b.r && a.ind < b.ind);
}

bool per(circle a, 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() {
    int n;
    cin >> n;
    vector<circle> cs(n);
    for (int i = 0; i < n; i++) {
        cin >> cs[i].x >> cs[i].y >> cs[i].r;
        cs[i].ind = i;
    }
    sort(cs.begin(), cs.end(), cmp);
    vector<int> ans(n, -1);
    for (int for_r = 30; for_r >= 0; for_r--) {
        int r = (1 << for_r);
        map<pair<int, int>, vector<int>> mp;
        bool flag = false;
        for (int i = 0; i < n; ++i) {
            if (ans[cs[i].ind] == -1 && cs[i].r >= r / 2 && cs[i].r <= r) {
                flag = true;
                break;
            }
        }
        if (!flag) continue;
        for (int i = 0; i < n; i++) {
            if (ans[cs[i].ind] == -1) {
                mp[{cs[i].x / r, cs[i].y / r}].push_back(i);
            }
        }
        for (int i = 0; i < n; i++) {
            if (cs[i].r < r / 2) break;
            if (cs[i].r > r || ans[cs[i].ind] != -1) continue;
            for (int x = cs[i].x / r - 2; x <= cs[i].x / r + 2; x++) {
                for (int y = cs[i].y / r - 2; y <= cs[i].y / r + 2; y++) {
                    if (mp.find({x, y}) == mp.end()) continue;
                    vector<int> &now = mp[{x, y}];
                    for (int j = (int) now.size() - 1; j >= 0; j--) {
                        int jj = now[j];
                        if (per(cs[i], cs[jj])) {
                            ans[cs[jj].ind] = cs[i].ind;
                            swap(now[j], now.back());
                            now.pop_back();
                        }
                    }
                }
            }
        }
    }
    for (int i: ans) {
        cout << i + 1 << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 3 ms 696 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 548 KB Output is correct
22 Correct 10 ms 1048 KB Output is correct
23 Correct 11 ms 1104 KB Output is correct
24 Correct 10 ms 1104 KB Output is correct
25 Correct 9 ms 1104 KB Output is correct
26 Correct 12 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 9368 KB Output is correct
2 Correct 128 ms 9252 KB Output is correct
3 Correct 127 ms 10572 KB Output is correct
4 Correct 156 ms 11508 KB Output is correct
5 Correct 178 ms 10568 KB Output is correct
6 Correct 548 ms 20880 KB Output is correct
7 Correct 203 ms 12872 KB Output is correct
8 Correct 263 ms 16012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 351 ms 14724 KB Output is correct
3 Correct 1581 ms 40960 KB Output is correct
4 Correct 1472 ms 49092 KB Output is correct
5 Correct 1468 ms 43456 KB Output is correct
6 Correct 460 ms 21832 KB Output is correct
7 Correct 176 ms 11536 KB Output is correct
8 Correct 25 ms 2744 KB Output is correct
9 Correct 1493 ms 47952 KB Output is correct
10 Correct 1287 ms 40660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1239 ms 41248 KB Output is correct
2 Correct 892 ms 48076 KB Output is correct
3 Correct 301 ms 24136 KB Output is correct
4 Correct 829 ms 48420 KB Output is correct
5 Correct 854 ms 48608 KB Output is correct
6 Correct 173 ms 19272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 3 ms 696 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 548 KB Output is correct
22 Correct 10 ms 1048 KB Output is correct
23 Correct 11 ms 1104 KB Output is correct
24 Correct 10 ms 1104 KB Output is correct
25 Correct 9 ms 1104 KB Output is correct
26 Correct 12 ms 1104 KB Output is correct
27 Correct 5 ms 592 KB Output is correct
28 Correct 5 ms 592 KB Output is correct
29 Correct 5 ms 592 KB Output is correct
30 Correct 23 ms 1616 KB Output is correct
31 Correct 23 ms 1748 KB Output is correct
32 Correct 21 ms 1616 KB Output is correct
33 Correct 42 ms 3136 KB Output is correct
34 Correct 43 ms 3136 KB Output is correct
35 Correct 46 ms 3128 KB Output is correct
36 Correct 322 ms 13876 KB Output is correct
37 Correct 284 ms 13840 KB Output is correct
38 Correct 320 ms 13912 KB Output is correct
39 Correct 255 ms 9124 KB Output is correct
40 Correct 246 ms 8968 KB Output is correct
41 Correct 256 ms 9124 KB Output is correct
42 Correct 154 ms 9552 KB Output is correct
43 Correct 206 ms 13640 KB Output is correct
44 Correct 214 ms 13748 KB Output is correct
45 Correct 214 ms 13612 KB Output is correct
46 Correct 204 ms 13640 KB Output is correct
47 Correct 220 ms 13640 KB Output is correct
48 Correct 194 ms 13640 KB Output is correct
49 Correct 198 ms 13644 KB Output is correct
50 Correct 236 ms 13624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 3 ms 696 KB Output is correct
20 Correct 3 ms 592 KB Output is correct
21 Correct 2 ms 548 KB Output is correct
22 Correct 10 ms 1048 KB Output is correct
23 Correct 11 ms 1104 KB Output is correct
24 Correct 10 ms 1104 KB Output is correct
25 Correct 9 ms 1104 KB Output is correct
26 Correct 12 ms 1104 KB Output is correct
27 Correct 152 ms 9368 KB Output is correct
28 Correct 128 ms 9252 KB Output is correct
29 Correct 127 ms 10572 KB Output is correct
30 Correct 156 ms 11508 KB Output is correct
31 Correct 178 ms 10568 KB Output is correct
32 Correct 548 ms 20880 KB Output is correct
33 Correct 203 ms 12872 KB Output is correct
34 Correct 263 ms 16012 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 351 ms 14724 KB Output is correct
37 Correct 1581 ms 40960 KB Output is correct
38 Correct 1472 ms 49092 KB Output is correct
39 Correct 1468 ms 43456 KB Output is correct
40 Correct 460 ms 21832 KB Output is correct
41 Correct 176 ms 11536 KB Output is correct
42 Correct 25 ms 2744 KB Output is correct
43 Correct 1493 ms 47952 KB Output is correct
44 Correct 1287 ms 40660 KB Output is correct
45 Correct 1239 ms 41248 KB Output is correct
46 Correct 892 ms 48076 KB Output is correct
47 Correct 301 ms 24136 KB Output is correct
48 Correct 829 ms 48420 KB Output is correct
49 Correct 854 ms 48608 KB Output is correct
50 Correct 173 ms 19272 KB Output is correct
51 Correct 5 ms 592 KB Output is correct
52 Correct 5 ms 592 KB Output is correct
53 Correct 5 ms 592 KB Output is correct
54 Correct 23 ms 1616 KB Output is correct
55 Correct 23 ms 1748 KB Output is correct
56 Correct 21 ms 1616 KB Output is correct
57 Correct 42 ms 3136 KB Output is correct
58 Correct 43 ms 3136 KB Output is correct
59 Correct 46 ms 3128 KB Output is correct
60 Correct 322 ms 13876 KB Output is correct
61 Correct 284 ms 13840 KB Output is correct
62 Correct 320 ms 13912 KB Output is correct
63 Correct 255 ms 9124 KB Output is correct
64 Correct 246 ms 8968 KB Output is correct
65 Correct 256 ms 9124 KB Output is correct
66 Correct 154 ms 9552 KB Output is correct
67 Correct 206 ms 13640 KB Output is correct
68 Correct 214 ms 13748 KB Output is correct
69 Correct 214 ms 13612 KB Output is correct
70 Correct 204 ms 13640 KB Output is correct
71 Correct 220 ms 13640 KB Output is correct
72 Correct 194 ms 13640 KB Output is correct
73 Correct 198 ms 13644 KB Output is correct
74 Correct 236 ms 13624 KB Output is correct
75 Correct 152 ms 17508 KB Output is correct
76 Correct 146 ms 17480 KB Output is correct
77 Correct 135 ms 18460 KB Output is correct
78 Correct 125 ms 18308 KB Output is correct
79 Correct 168 ms 17164 KB Output is correct
80 Correct 140 ms 18520 KB Output is correct
81 Correct 1622 ms 49024 KB Output is correct
82 Correct 1326 ms 48876 KB Output is correct
83 Correct 1412 ms 48812 KB Output is correct
84 Correct 1215 ms 49480 KB Output is correct
85 Correct 1286 ms 48848 KB Output is correct
86 Correct 1285 ms 48968 KB Output is correct
87 Correct 1642 ms 48720 KB Output is correct
88 Correct 1110 ms 30068 KB Output is correct
89 Correct 1140 ms 30060 KB Output is correct
90 Correct 1036 ms 30096 KB Output is correct
91 Correct 1110 ms 29892 KB Output is correct
92 Correct 940 ms 29848 KB Output is correct
93 Correct 1126 ms 47888 KB Output is correct
94 Correct 998 ms 48232 KB Output is correct
95 Correct 1212 ms 48008 KB Output is correct
96 Correct 1239 ms 47752 KB Output is correct
97 Correct 1571 ms 47832 KB Output is correct
98 Correct 591 ms 31296 KB Output is correct
99 Correct 1071 ms 48200 KB Output is correct
100 Correct 897 ms 47944 KB Output is correct
101 Correct 808 ms 36876 KB Output is correct
102 Correct 1062 ms 47284 KB Output is correct
103 Correct 1642 ms 46524 KB Output is correct
104 Correct 1139 ms 47944 KB Output is correct
105 Correct 716 ms 32788 KB Output is correct
106 Correct 848 ms 46664 KB Output is correct
107 Correct 704 ms 46664 KB Output is correct
108 Correct 826 ms 46548 KB Output is correct
109 Correct 760 ms 46484 KB Output is correct
110 Correct 669 ms 46664 KB Output is correct
111 Correct 725 ms 46540 KB Output is correct
112 Correct 726 ms 46544 KB Output is correct
113 Correct 763 ms 46664 KB Output is correct
114 Correct 813 ms 46568 KB Output is correct
115 Correct 805 ms 46664 KB Output is correct
116 Correct 664 ms 46664 KB Output is correct