Submission #103656

# Submission time Handle Problem Language Result Execution time Memory
103656 2019-04-01T19:57:24 Z osaaateiasavtnl Circle selection (APIO18_circle_selection) C++14
72 / 100
3000 ms 46688 KB
#include<bits/stdc++.h>
using namespace std;
#define Point pair <int, int>
#define x first
#define y second
const int N = 3e5 + 7;
int n;
Point a[N];
int r[N];
int par[N];
int cur = 1 << 30;
vector<vector<int>> av;
vector<int> px;
int per[N];
bool compx(int i, int j) {
    return a[i].x < a[j].x;
}   
bool compy(int i, int j) {
    return a[i].y < a[j].y;
}   
bool used[N];
struct Comp {
    bool operator () (const int i, const int j) {
        return (r[i] > r[j]) || (r[i] == r[j] && i < j);
    }   
};
set <int,Comp> ms;
void build() {
    av.clear(); px.clear();
    int ptr = 0;
    while (ptr < n) {
        int r = ptr;
        while (r + 1 < n && a[per[ptr]].x / cur == a[per[r + 1]].x / cur) ++r;
        av.push_back({});
        for (int i = ptr; i <= r; ++i) {
            av.back().push_back(per[i]);
        }
        sort(av.back().begin(), av.back().end(), compy);
        px.push_back(a[per[ptr]].x / cur);
        ptr = r + 1;
    }   
}   
bool intersect(int i, int j) {
    typedef long long ll;
    return (ll)(a[i].x - a[j].x) * (a[i].x - a[j].x) + (ll)(a[i].y - a[j].y) * (a[i].y - a[j].y) <= (ll)(r[i] + r[j]) * (r[i] + r[j]);
}   
void check(int el, int i) {
    #ifdef HOME
    cout << "check " << el + 1 << ' ' << i + 1 << '\n';
    #endif
    if (used[i]) return;
    if (intersect(el, i)) {
        used[i] = 1;
        par[i] = el;
        ms.erase(i);
    }   
}   
void work(int el, int x, int y) {
    auto t = lower_bound(px.begin(), px.end(), x);
    if (*t == x) {
        int pos = t - px.begin();
        #ifdef HOME
        cout << "work " << el + 1 << ' ' << pos << '\n';
        #endif
        int l = -1, r = av[pos].size();
        while (l < r - 1) {
            int m = (l + r) >> 1;
            int i = av[pos][m];
            if (a[i].y / cur < y) l = m;
            else r = m;
        }   
        for (int i = r; i < (int)av[pos].size(); ++i) {
            if (a[av[pos][i]].y / cur != y) {
                break;
            }   
            check(el, av[pos][i]);
        }
    }   
}
void print_struct() {
    for (int i = 0; i < (int)av.size(); ++i) {
        cout << px[i] << " : ";
        for (int t : av[i]) cout << t + 1 << ' ';
        cout << '\n';
    }   
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].x >> a[i].y >> r[i];
    }   
    for (int i = 0; i < n; ++i) {
        per[i] = i;
    }   
    sort(per, per + n, compx);
    for (int i = 0; i < n; ++i) {
        ms.insert(i);
    }   
    build();
    while (ms.size()) {
        int i = *ms.begin();
        while ((cur >> 1) >= r[i]) {
            cur >>= 1;
            build();
        }
        #ifdef HOME
        cout << "eliminate " << i + 1 << '\n';
        cout << "cur " << cur << '\n';
        print_struct();
        #endif
        int ix = a[i].x / cur, iy = a[i].y / cur;
        for (int dx = -2; dx <= 2; ++dx) {
            for (int dy = -2; dy <= 2; ++dy) {
                work(i, ix + dx, iy + dy);
            }   
        }   
    }   
    for (int i = 0; i < n; ++i) {
        cout << par[i] + 1 << ' ';
    }   
    cout << '\n';
}   
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 9 ms 896 KB Output is correct
20 Correct 8 ms 896 KB Output is correct
21 Correct 12 ms 896 KB Output is correct
22 Correct 25 ms 1340 KB Output is correct
23 Correct 29 ms 1180 KB Output is correct
24 Correct 24 ms 1152 KB Output is correct
25 Correct 25 ms 1152 KB Output is correct
26 Correct 24 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 789 ms 31724 KB Output is correct
2 Correct 845 ms 31392 KB Output is correct
3 Correct 802 ms 31140 KB Output is correct
4 Correct 819 ms 31428 KB Output is correct
5 Correct 1232 ms 34704 KB Output is correct
6 Correct 1738 ms 43544 KB Output is correct
7 Correct 1428 ms 40436 KB Output is correct
8 Correct 1512 ms 42808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 869 ms 14124 KB Output is correct
3 Execution timed out 3040 ms 46688 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1980 ms 34836 KB Output is correct
2 Correct 2117 ms 46268 KB Output is correct
3 Correct 1187 ms 29684 KB Output is correct
4 Correct 1864 ms 46156 KB Output is correct
5 Correct 1842 ms 46236 KB Output is correct
6 Correct 1171 ms 29936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 9 ms 896 KB Output is correct
20 Correct 8 ms 896 KB Output is correct
21 Correct 12 ms 896 KB Output is correct
22 Correct 25 ms 1340 KB Output is correct
23 Correct 29 ms 1180 KB Output is correct
24 Correct 24 ms 1152 KB Output is correct
25 Correct 25 ms 1152 KB Output is correct
26 Correct 24 ms 1280 KB Output is correct
27 Correct 23 ms 1408 KB Output is correct
28 Correct 18 ms 1536 KB Output is correct
29 Correct 17 ms 1516 KB Output is correct
30 Correct 68 ms 1912 KB Output is correct
31 Correct 46 ms 2036 KB Output is correct
32 Correct 50 ms 2036 KB Output is correct
33 Correct 196 ms 11376 KB Output is correct
34 Correct 201 ms 11336 KB Output is correct
35 Correct 352 ms 10744 KB Output is correct
36 Correct 794 ms 14864 KB Output is correct
37 Correct 832 ms 14952 KB Output is correct
38 Correct 901 ms 14928 KB Output is correct
39 Correct 754 ms 9360 KB Output is correct
40 Correct 786 ms 9448 KB Output is correct
41 Correct 731 ms 9480 KB Output is correct
42 Correct 524 ms 9908 KB Output is correct
43 Correct 410 ms 16040 KB Output is correct
44 Correct 384 ms 16072 KB Output is correct
45 Correct 464 ms 16120 KB Output is correct
46 Correct 414 ms 16068 KB Output is correct
47 Correct 427 ms 16144 KB Output is correct
48 Correct 381 ms 15992 KB Output is correct
49 Correct 415 ms 16156 KB Output is correct
50 Correct 382 ms 15988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 484 KB Output is correct
17 Correct 4 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 9 ms 896 KB Output is correct
20 Correct 8 ms 896 KB Output is correct
21 Correct 12 ms 896 KB Output is correct
22 Correct 25 ms 1340 KB Output is correct
23 Correct 29 ms 1180 KB Output is correct
24 Correct 24 ms 1152 KB Output is correct
25 Correct 25 ms 1152 KB Output is correct
26 Correct 24 ms 1280 KB Output is correct
27 Correct 789 ms 31724 KB Output is correct
28 Correct 845 ms 31392 KB Output is correct
29 Correct 802 ms 31140 KB Output is correct
30 Correct 819 ms 31428 KB Output is correct
31 Correct 1232 ms 34704 KB Output is correct
32 Correct 1738 ms 43544 KB Output is correct
33 Correct 1428 ms 40436 KB Output is correct
34 Correct 1512 ms 42808 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 869 ms 14124 KB Output is correct
37 Execution timed out 3040 ms 46688 KB Time limit exceeded
38 Halted 0 ms 0 KB -