Submission #87167

# Submission time Handle Problem Language Result Execution time Memory
87167 2018-11-29T19:44:52 Z fedoseevtimofey Circle selection (APIO18_circle_selection) C++14
100 / 100
2642 ms 89680 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int n;
vector <int> x, y, r;
vector <int> _kill;
 
void init() {
    cin >> n;
    x.resize(n);
    y.resize(n);
    r.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i] >> r[i];
    }
}
 
bool inter(int i, int j) {
    return (ll)(x[i] - x[j]) * (x[i] - x[j]) + (ll)(y[i] - y[j]) * (y[i] - y[j]) <= (ll)(r[i] + r[j]) * (r[i] + r[j]);
}
 
map <pair <int, int>, vector <int>> who;
 
 
void rebuild(int B) {
    who.clear();
    for (int i = 0; i < n; ++i) {
        if (_kill[i] != -1) continue;
        int xx = x[i] / B;
        int yy = y[i] / B;
        who[make_pair(xx, yy)].push_back(i);
    }
}
 
void solve() {
    _kill.resize(n, -1);
    vector <int> idx(n);
    iota(idx.begin(), idx.end(), 0);
    sort(idx.begin(), idx.end(), [&] (int i, int j) {
        if (r[i] != r[j]) return r[i] > r[j];
        return i < j;
    });
    int uk = 0;
    int B = 2e9 + 7;
    while (true) {
        while (uk < n && _kill[idx[uk]] != -1) ++uk;
        if (uk == n) break;
        int cur = idx[uk];
        if ((r[cur] << 1) <= B) {
            B = r[cur];
            rebuild(B);
        }
        _kill[cur] = cur;
        int xx = x[cur] / B;
        int yy = y[cur] / B;
        for (int cx = xx - 2; cx <= xx + 2; ++cx) {
            for (int cy = yy - 2; cy <= yy + 2; ++cy) {
                if (who.count(make_pair(cx, cy))) {
                    vector <int> nw;
                    for (auto j : who[make_pair(cx, cy)]) {
                        if (inter(cur, j)) {
                            _kill[j] = cur;
                        }
                        else nw.push_back(j);
                    }
                    who[make_pair(cx, cy)] = nw;
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << _kill[i] + 1 << ' ';
    }
}
 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    init();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 780 KB Output is correct
12 Correct 3 ms 780 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 2 ms 780 KB Output is correct
16 Correct 3 ms 780 KB Output is correct
17 Correct 3 ms 780 KB Output is correct
18 Correct 3 ms 780 KB Output is correct
19 Correct 5 ms 888 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 8 ms 904 KB Output is correct
22 Correct 18 ms 1416 KB Output is correct
23 Correct 19 ms 1560 KB Output is correct
24 Correct 18 ms 1560 KB Output is correct
25 Correct 17 ms 1576 KB Output is correct
26 Correct 17 ms 1576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 11936 KB Output is correct
2 Correct 197 ms 12672 KB Output is correct
3 Correct 197 ms 13508 KB Output is correct
4 Correct 189 ms 13508 KB Output is correct
5 Correct 261 ms 13508 KB Output is correct
6 Correct 913 ms 30140 KB Output is correct
7 Correct 327 ms 30140 KB Output is correct
8 Correct 554 ms 30140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 30140 KB Output is correct
2 Correct 625 ms 30140 KB Output is correct
3 Correct 2409 ms 47944 KB Output is correct
4 Correct 2248 ms 56016 KB Output is correct
5 Correct 2112 ms 57584 KB Output is correct
6 Correct 750 ms 57584 KB Output is correct
7 Correct 294 ms 57584 KB Output is correct
8 Correct 43 ms 57584 KB Output is correct
9 Correct 2535 ms 78312 KB Output is correct
10 Correct 1954 ms 79716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1958 ms 87544 KB Output is correct
2 Correct 1347 ms 89528 KB Output is correct
3 Correct 619 ms 89528 KB Output is correct
4 Correct 1498 ms 89572 KB Output is correct
5 Correct 1422 ms 89572 KB Output is correct
6 Correct 303 ms 89572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 780 KB Output is correct
12 Correct 3 ms 780 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 2 ms 780 KB Output is correct
16 Correct 3 ms 780 KB Output is correct
17 Correct 3 ms 780 KB Output is correct
18 Correct 3 ms 780 KB Output is correct
19 Correct 5 ms 888 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 8 ms 904 KB Output is correct
22 Correct 18 ms 1416 KB Output is correct
23 Correct 19 ms 1560 KB Output is correct
24 Correct 18 ms 1560 KB Output is correct
25 Correct 17 ms 1576 KB Output is correct
26 Correct 17 ms 1576 KB Output is correct
27 Correct 8 ms 89572 KB Output is correct
28 Correct 8 ms 89572 KB Output is correct
29 Correct 9 ms 89572 KB Output is correct
30 Correct 38 ms 89572 KB Output is correct
31 Correct 34 ms 89572 KB Output is correct
32 Correct 36 ms 89572 KB Output is correct
33 Correct 81 ms 89572 KB Output is correct
34 Correct 67 ms 89572 KB Output is correct
35 Correct 71 ms 89572 KB Output is correct
36 Correct 474 ms 89572 KB Output is correct
37 Correct 497 ms 89572 KB Output is correct
38 Correct 551 ms 89572 KB Output is correct
39 Correct 455 ms 89572 KB Output is correct
40 Correct 435 ms 89572 KB Output is correct
41 Correct 452 ms 89572 KB Output is correct
42 Correct 376 ms 89572 KB Output is correct
43 Correct 371 ms 89572 KB Output is correct
44 Correct 370 ms 89572 KB Output is correct
45 Correct 333 ms 89572 KB Output is correct
46 Correct 346 ms 89572 KB Output is correct
47 Correct 350 ms 89572 KB Output is correct
48 Correct 337 ms 89572 KB Output is correct
49 Correct 341 ms 89572 KB Output is correct
50 Correct 352 ms 89572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 584 KB Output is correct
4 Correct 2 ms 584 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 584 KB Output is correct
7 Correct 2 ms 584 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 780 KB Output is correct
12 Correct 3 ms 780 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 3 ms 780 KB Output is correct
15 Correct 2 ms 780 KB Output is correct
16 Correct 3 ms 780 KB Output is correct
17 Correct 3 ms 780 KB Output is correct
18 Correct 3 ms 780 KB Output is correct
19 Correct 5 ms 888 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 8 ms 904 KB Output is correct
22 Correct 18 ms 1416 KB Output is correct
23 Correct 19 ms 1560 KB Output is correct
24 Correct 18 ms 1560 KB Output is correct
25 Correct 17 ms 1576 KB Output is correct
26 Correct 17 ms 1576 KB Output is correct
27 Correct 195 ms 11936 KB Output is correct
28 Correct 197 ms 12672 KB Output is correct
29 Correct 197 ms 13508 KB Output is correct
30 Correct 189 ms 13508 KB Output is correct
31 Correct 261 ms 13508 KB Output is correct
32 Correct 913 ms 30140 KB Output is correct
33 Correct 327 ms 30140 KB Output is correct
34 Correct 554 ms 30140 KB Output is correct
35 Correct 3 ms 30140 KB Output is correct
36 Correct 625 ms 30140 KB Output is correct
37 Correct 2409 ms 47944 KB Output is correct
38 Correct 2248 ms 56016 KB Output is correct
39 Correct 2112 ms 57584 KB Output is correct
40 Correct 750 ms 57584 KB Output is correct
41 Correct 294 ms 57584 KB Output is correct
42 Correct 43 ms 57584 KB Output is correct
43 Correct 2535 ms 78312 KB Output is correct
44 Correct 1954 ms 79716 KB Output is correct
45 Correct 1958 ms 87544 KB Output is correct
46 Correct 1347 ms 89528 KB Output is correct
47 Correct 619 ms 89528 KB Output is correct
48 Correct 1498 ms 89572 KB Output is correct
49 Correct 1422 ms 89572 KB Output is correct
50 Correct 303 ms 89572 KB Output is correct
51 Correct 8 ms 89572 KB Output is correct
52 Correct 8 ms 89572 KB Output is correct
53 Correct 9 ms 89572 KB Output is correct
54 Correct 38 ms 89572 KB Output is correct
55 Correct 34 ms 89572 KB Output is correct
56 Correct 36 ms 89572 KB Output is correct
57 Correct 81 ms 89572 KB Output is correct
58 Correct 67 ms 89572 KB Output is correct
59 Correct 71 ms 89572 KB Output is correct
60 Correct 474 ms 89572 KB Output is correct
61 Correct 497 ms 89572 KB Output is correct
62 Correct 551 ms 89572 KB Output is correct
63 Correct 455 ms 89572 KB Output is correct
64 Correct 435 ms 89572 KB Output is correct
65 Correct 452 ms 89572 KB Output is correct
66 Correct 376 ms 89572 KB Output is correct
67 Correct 371 ms 89572 KB Output is correct
68 Correct 370 ms 89572 KB Output is correct
69 Correct 333 ms 89572 KB Output is correct
70 Correct 346 ms 89572 KB Output is correct
71 Correct 350 ms 89572 KB Output is correct
72 Correct 337 ms 89572 KB Output is correct
73 Correct 341 ms 89572 KB Output is correct
74 Correct 352 ms 89572 KB Output is correct
75 Correct 231 ms 89572 KB Output is correct
76 Correct 222 ms 89572 KB Output is correct
77 Correct 203 ms 89572 KB Output is correct
78 Correct 199 ms 89572 KB Output is correct
79 Correct 282 ms 89572 KB Output is correct
80 Correct 198 ms 89572 KB Output is correct
81 Correct 2125 ms 89572 KB Output is correct
82 Correct 2028 ms 89572 KB Output is correct
83 Correct 2066 ms 89572 KB Output is correct
84 Correct 2217 ms 89572 KB Output is correct
85 Correct 2045 ms 89572 KB Output is correct
86 Correct 2085 ms 89572 KB Output is correct
87 Correct 2642 ms 89572 KB Output is correct
88 Correct 1640 ms 89572 KB Output is correct
89 Correct 1614 ms 89572 KB Output is correct
90 Correct 1670 ms 89572 KB Output is correct
91 Correct 1645 ms 89572 KB Output is correct
92 Correct 1656 ms 89572 KB Output is correct
93 Correct 1621 ms 89672 KB Output is correct
94 Correct 1760 ms 89672 KB Output is correct
95 Correct 1522 ms 89672 KB Output is correct
96 Correct 1645 ms 89672 KB Output is correct
97 Correct 2423 ms 89672 KB Output is correct
98 Correct 1097 ms 89672 KB Output is correct
99 Correct 1686 ms 89672 KB Output is correct
100 Correct 1550 ms 89680 KB Output is correct
101 Correct 1592 ms 89680 KB Output is correct
102 Correct 1755 ms 89680 KB Output is correct
103 Correct 2613 ms 89680 KB Output is correct
104 Correct 1706 ms 89680 KB Output is correct
105 Correct 1491 ms 89680 KB Output is correct
106 Correct 1304 ms 89680 KB Output is correct
107 Correct 1275 ms 89680 KB Output is correct
108 Correct 1364 ms 89680 KB Output is correct
109 Correct 1302 ms 89680 KB Output is correct
110 Correct 1294 ms 89680 KB Output is correct
111 Correct 1312 ms 89680 KB Output is correct
112 Correct 1309 ms 89680 KB Output is correct
113 Correct 1261 ms 89680 KB Output is correct
114 Correct 1285 ms 89680 KB Output is correct
115 Correct 1301 ms 89680 KB Output is correct
116 Correct 1252 ms 89680 KB Output is correct