Submission #87158

# Submission time Handle Problem Language Result Execution time Memory
87158 2018-11-29T19:06:02 Z fedoseevtimofey Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 407652 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int n;
vector <int> x, y, r;
 
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;
 
set <int> alive;
 
void rebuild(int B) {
    who.clear();
    for (auto i : alive) {
        int xx = x[i] / B;
        int yy = y[i] / B;
        who[make_pair(xx, yy)].push_back(i);
    }
}
 
void solve() {
    for (int i = 0; i < n; ++i) alive.insert(i);
    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;
    });
    vector <int> kill(n, -1);
    int uk = 0;
    for (int B = 1 << 30; B > 0; B >>= 1) {
        bool fl = false;
        while (true) {
            while (uk < n && kill[idx[uk]] != -1) ++uk;
            if (uk == n) break;
            int cur = idx[uk];
            if (!fl) {
                B = r[cur];
                rebuild(B);
                fl = true; 
            }
            else {
                if (B >> 1 >= r[cur]) break;
            }
            alive.erase(cur);
            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) {
                    for (auto j : who[make_pair(cx, cy)]) {
                        if (kill[j] != -1) continue;
                        if (inter(cur, j)) {
                            kill[j] = cur;
                            alive.erase(j);
                        }
                    }
                }
            }
        }
    }
    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 416 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 2 ms 420 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 420 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 3 ms 624 KB Output is correct
14 Correct 3 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 3 ms 796 KB Output is correct
18 Correct 3 ms 796 KB Output is correct
19 Correct 6 ms 988 KB Output is correct
20 Correct 6 ms 988 KB Output is correct
21 Correct 6 ms 1008 KB Output is correct
22 Correct 41 ms 6140 KB Output is correct
23 Correct 44 ms 6140 KB Output is correct
24 Correct 40 ms 6156 KB Output is correct
25 Correct 39 ms 6156 KB Output is correct
26 Correct 44 ms 6172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 22960 KB Output is correct
2 Correct 362 ms 23868 KB Output is correct
3 Correct 331 ms 23952 KB Output is correct
4 Correct 360 ms 23952 KB Output is correct
5 Correct 651 ms 23952 KB Output is correct
6 Correct 1814 ms 88280 KB Output is correct
7 Correct 706 ms 88280 KB Output is correct
8 Correct 910 ms 88280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 88280 KB Output is correct
2 Correct 1643 ms 109960 KB Output is correct
3 Execution timed out 3058 ms 329312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 407652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 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 416 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 2 ms 420 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 420 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 3 ms 624 KB Output is correct
14 Correct 3 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 3 ms 796 KB Output is correct
18 Correct 3 ms 796 KB Output is correct
19 Correct 6 ms 988 KB Output is correct
20 Correct 6 ms 988 KB Output is correct
21 Correct 6 ms 1008 KB Output is correct
22 Correct 41 ms 6140 KB Output is correct
23 Correct 44 ms 6140 KB Output is correct
24 Correct 40 ms 6156 KB Output is correct
25 Correct 39 ms 6156 KB Output is correct
26 Correct 44 ms 6172 KB Output is correct
27 Correct 11 ms 407652 KB Output is correct
28 Correct 17 ms 407652 KB Output is correct
29 Correct 11 ms 407652 KB Output is correct
30 Correct 101 ms 407652 KB Output is correct
31 Correct 97 ms 407652 KB Output is correct
32 Correct 96 ms 407652 KB Output is correct
33 Correct 121 ms 407652 KB Output is correct
34 Correct 107 ms 407652 KB Output is correct
35 Correct 127 ms 407652 KB Output is correct
36 Correct 1515 ms 407652 KB Output is correct
37 Correct 1504 ms 407652 KB Output is correct
38 Correct 1781 ms 407652 KB Output is correct
39 Correct 682 ms 407652 KB Output is correct
40 Correct 685 ms 407652 KB Output is correct
41 Correct 696 ms 407652 KB Output is correct
42 Correct 391 ms 407652 KB Output is correct
43 Correct 1118 ms 407652 KB Output is correct
44 Correct 1184 ms 407652 KB Output is correct
45 Correct 1161 ms 407652 KB Output is correct
46 Correct 1197 ms 407652 KB Output is correct
47 Correct 1155 ms 407652 KB Output is correct
48 Correct 1169 ms 407652 KB Output is correct
49 Correct 1144 ms 407652 KB Output is correct
50 Correct 1134 ms 407652 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 416 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 420 KB Output is correct
6 Correct 2 ms 420 KB Output is correct
7 Correct 2 ms 420 KB Output is correct
8 Correct 2 ms 420 KB Output is correct
9 Correct 2 ms 420 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 2 ms 608 KB Output is correct
13 Correct 3 ms 624 KB Output is correct
14 Correct 3 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 3 ms 796 KB Output is correct
18 Correct 3 ms 796 KB Output is correct
19 Correct 6 ms 988 KB Output is correct
20 Correct 6 ms 988 KB Output is correct
21 Correct 6 ms 1008 KB Output is correct
22 Correct 41 ms 6140 KB Output is correct
23 Correct 44 ms 6140 KB Output is correct
24 Correct 40 ms 6156 KB Output is correct
25 Correct 39 ms 6156 KB Output is correct
26 Correct 44 ms 6172 KB Output is correct
27 Correct 330 ms 22960 KB Output is correct
28 Correct 362 ms 23868 KB Output is correct
29 Correct 331 ms 23952 KB Output is correct
30 Correct 360 ms 23952 KB Output is correct
31 Correct 651 ms 23952 KB Output is correct
32 Correct 1814 ms 88280 KB Output is correct
33 Correct 706 ms 88280 KB Output is correct
34 Correct 910 ms 88280 KB Output is correct
35 Correct 2 ms 88280 KB Output is correct
36 Correct 1643 ms 109960 KB Output is correct
37 Execution timed out 3058 ms 329312 KB Time limit exceeded
38 Halted 0 ms 0 KB -