Submission #1075360

# Submission time Handle Problem Language Result Execution time Memory
1075360 2024-08-26T04:22:26 Z ngrace Circle selection (APIO18_circle_selection) C++14
100 / 100
1840 ms 55136 KB
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

struct Circle{
    ll x, y, r, i;
};

int N;
v<Circle> C;

bool compC(Circle& a, Circle& b){
    if(a.r==b.r) return a.i<b.i;
    return a.r>b.r;
}
bool isect(Circle& a, Circle& b){
    ll dx=a.x-b.x;
    ll dy=a.y-b.y;
    ll r=a.r+b.r;
    return dx*dx+dy*dy <= r*r;
}

v<ll> eBy;

void sub1(){
    for(int i=0; i<N; i++){
        if(eBy[C[i].i]!=-1) continue;
        eBy[C[i].i] = C[i].i;
        for(int j=i+1; j<N; j++){
            if(eBy[C[j].i]==-1 && isect(C[i], C[j])){
                eBy[C[j].i] = C[i].i;
            }
        }
    }
}

void sub2(){
    set<ii> pts;
    for(int i=0; i<N; i++){
        pts.insert(make_pair(C[i].x-C[i].r, i));
        pts.insert(make_pair(C[i].x+C[i].r, i));
    }

    for(int i=0; i<N; i++){
        if(eBy[C[i].i]!=-1) continue;
        v<int> del;
        auto it = pts.lower_bound(make_pair(C[i].x-C[i].r, -1));
        while(it!=pts.end() && (*it).fi<=C[i].x+C[i].r){
            del.push_back((*it).se);
            it++;
        }
        for(int ind:del){
            eBy[C[ind].i] = C[i].i;
            pts.erase(make_pair(C[ind].x-C[ind].r, ind));
            pts.erase(make_pair(C[ind].x+C[ind].r, ind));
        }
    }
}

void sub3(){
    set<ii> xs;
    set<ii> ys;
    for(int i=0; i<N; i++){
        ys.insert({C[i].y-C[i].r, i});
        ys.insert({C[i].y+C[i].r, i});
        eBy[i] = i;
    }
    for(ii y:ys){
        ll x = C[y.se].x;

        if(C[y.se].y+C[y.se].r==y.fi) xs.erase({x,y.se});

        auto it = xs.lower_bound({x,-1});
        if(it!=xs.end()){
            ll ind = (*it).se;
            if(isect(C[y.se], C[ind])){
                ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
                eBy[C[y.se].i] = C[e].i;
                eBy[C[ind].i] = C[e].i;
            }
        }
        if(it!=xs.begin()){
            it--;
            ll ind = (*it).se;
            if(isect(C[y.se], C[ind])){
                ll e = (compC(C[y.se], C[ind]) ? y.se : ind);
                eBy[C[y.se].i] = C[e].i;
                eBy[C[ind].i] = C[e].i;
            }
        }

        if(C[y.se].y-C[y.se].r == y.fi) xs.insert({x,y.se});
    }
}

void sub4(){
    map<ii, v<ll>> grid;
    for(int i=0; i<N; i++){
        grid[{C[i].x/C[i].r, C[i].y/C[i].r}].push_back(i);
    }
    for(int i=0; i<N; i++){
        Circle& cur = C[i];
        if(eBy[cur.i]!=-1) continue;
        for(ll x=cur.x/cur.r - 2; x<=cur.x/cur.r+2; x++){
            for(ll y=cur.y/cur.r-2; y<=cur.y/cur.r+2; y++){
                if(grid.find({x,y})==grid.end()) continue;
                for(ll c:grid[{x,y}]){
                    if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
                }
            }
        }
    }
}

void full(){
    map<ii, v<ll>> grid;
    for(ll ri = 30; ri>=0; ri--){
        ll r = (1<<ri);
        bool skip=true;
        for(int i=0; i<N; i++){
            if(eBy[C[i].i]==-1 && C[i].r>=r/2 && C[i].r<=r){
                skip=false;
                break;
            }
        }
        if(skip) continue;
        grid.clear();
        for(int i=0; i<N; i++){
            if(eBy[C[i].i]!=-1) continue;
            grid[{C[i].x/r, C[i].y/r}].push_back(i);
        }
        for(int i=0; i<N; i++){
            Circle& cur = C[i];
            if(cur.r<r/2) break;
            if(eBy[cur.i]!=-1 || cur.r>r) continue;
            for(ll x=cur.x/r - 2; x<=cur.x/r+2; x++){
                for(ll y=cur.y/r-2; y<=cur.y/r+2; y++){
                    if(grid.find({x,y})==grid.end()) continue;
                    for(ll c:grid[{x,y}]){
                        if(eBy[C[c].i]==-1 && isect(C[c],cur)) eBy[C[c].i] = cur.i;
                    }
                }
            }
        }
    }
}

int main(){
    cin>>N;
    bool s2 = true;
    bool s4 = true;
    for(int i=0; i<N; i++){
        ll x,y,r;
        cin>>x>>y>>r;
        C.push_back({x,y,r,i});
        s2 = s2 && y==0;
        s4 = s4 && r==C[0].r;
    }
    sort(C.begin(), C.end(), compC);

    eBy = v<ll>(N,-1);

    if(s4) sub4();
    else full();
    // if(N<=5000) sub1();
    // else if(s2) sub2();
    // else if(s4) sub4();
    // else sub3();

    for(int i:eBy) cout<<i+1<<" ";
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 528 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 13 ms 1320 KB Output is correct
23 Correct 14 ms 1324 KB Output is correct
24 Correct 16 ms 1236 KB Output is correct
25 Correct 12 ms 1240 KB Output is correct
26 Correct 13 ms 1172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 273 ms 27284 KB Output is correct
2 Correct 256 ms 25280 KB Output is correct
3 Correct 257 ms 24608 KB Output is correct
4 Correct 253 ms 27288 KB Output is correct
5 Correct 280 ms 22684 KB Output is correct
6 Correct 639 ms 32916 KB Output is correct
7 Correct 313 ms 24216 KB Output is correct
8 Correct 368 ms 26260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 410 ms 18640 KB Output is correct
3 Correct 1443 ms 54928 KB Output is correct
4 Correct 1443 ms 54932 KB Output is correct
5 Correct 1455 ms 49392 KB Output is correct
6 Correct 489 ms 24744 KB Output is correct
7 Correct 213 ms 13116 KB Output is correct
8 Correct 36 ms 3020 KB Output is correct
9 Correct 1622 ms 53912 KB Output is correct
10 Correct 1200 ms 46744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1217 ms 54924 KB Output is correct
2 Correct 889 ms 53908 KB Output is correct
3 Correct 475 ms 33908 KB Output is correct
4 Correct 974 ms 54420 KB Output is correct
5 Correct 944 ms 54472 KB Output is correct
6 Correct 348 ms 27796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 528 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 13 ms 1320 KB Output is correct
23 Correct 14 ms 1324 KB Output is correct
24 Correct 16 ms 1236 KB Output is correct
25 Correct 12 ms 1240 KB Output is correct
26 Correct 13 ms 1172 KB Output is correct
27 Correct 15 ms 1492 KB Output is correct
28 Correct 10 ms 1240 KB Output is correct
29 Correct 10 ms 1240 KB Output is correct
30 Correct 29 ms 2004 KB Output is correct
31 Correct 28 ms 2200 KB Output is correct
32 Correct 27 ms 2004 KB Output is correct
33 Correct 104 ms 9652 KB Output is correct
34 Correct 108 ms 9656 KB Output is correct
35 Correct 106 ms 9140 KB Output is correct
36 Correct 359 ms 18360 KB Output is correct
37 Correct 360 ms 18356 KB Output is correct
38 Correct 385 ms 18360 KB Output is correct
39 Correct 289 ms 12212 KB Output is correct
40 Correct 289 ms 12320 KB Output is correct
41 Correct 289 ms 12324 KB Output is correct
42 Correct 217 ms 17332 KB Output is correct
43 Correct 272 ms 18356 KB Output is correct
44 Correct 259 ms 18108 KB Output is correct
45 Correct 259 ms 18360 KB Output is correct
46 Correct 253 ms 18032 KB Output is correct
47 Correct 260 ms 18100 KB Output is correct
48 Correct 264 ms 18104 KB Output is correct
49 Correct 258 ms 18028 KB Output is correct
50 Correct 257 ms 18100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 528 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 5 ms 860 KB Output is correct
21 Correct 5 ms 860 KB Output is correct
22 Correct 13 ms 1320 KB Output is correct
23 Correct 14 ms 1324 KB Output is correct
24 Correct 16 ms 1236 KB Output is correct
25 Correct 12 ms 1240 KB Output is correct
26 Correct 13 ms 1172 KB Output is correct
27 Correct 273 ms 27284 KB Output is correct
28 Correct 256 ms 25280 KB Output is correct
29 Correct 257 ms 24608 KB Output is correct
30 Correct 253 ms 27288 KB Output is correct
31 Correct 280 ms 22684 KB Output is correct
32 Correct 639 ms 32916 KB Output is correct
33 Correct 313 ms 24216 KB Output is correct
34 Correct 368 ms 26260 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 410 ms 18640 KB Output is correct
37 Correct 1443 ms 54928 KB Output is correct
38 Correct 1443 ms 54932 KB Output is correct
39 Correct 1455 ms 49392 KB Output is correct
40 Correct 489 ms 24744 KB Output is correct
41 Correct 213 ms 13116 KB Output is correct
42 Correct 36 ms 3020 KB Output is correct
43 Correct 1622 ms 53912 KB Output is correct
44 Correct 1200 ms 46744 KB Output is correct
45 Correct 1217 ms 54924 KB Output is correct
46 Correct 889 ms 53908 KB Output is correct
47 Correct 475 ms 33908 KB Output is correct
48 Correct 974 ms 54420 KB Output is correct
49 Correct 944 ms 54472 KB Output is correct
50 Correct 348 ms 27796 KB Output is correct
51 Correct 15 ms 1492 KB Output is correct
52 Correct 10 ms 1240 KB Output is correct
53 Correct 10 ms 1240 KB Output is correct
54 Correct 29 ms 2004 KB Output is correct
55 Correct 28 ms 2200 KB Output is correct
56 Correct 27 ms 2004 KB Output is correct
57 Correct 104 ms 9652 KB Output is correct
58 Correct 108 ms 9656 KB Output is correct
59 Correct 106 ms 9140 KB Output is correct
60 Correct 359 ms 18360 KB Output is correct
61 Correct 360 ms 18356 KB Output is correct
62 Correct 385 ms 18360 KB Output is correct
63 Correct 289 ms 12212 KB Output is correct
64 Correct 289 ms 12320 KB Output is correct
65 Correct 289 ms 12324 KB Output is correct
66 Correct 217 ms 17332 KB Output is correct
67 Correct 272 ms 18356 KB Output is correct
68 Correct 259 ms 18108 KB Output is correct
69 Correct 259 ms 18360 KB Output is correct
70 Correct 253 ms 18032 KB Output is correct
71 Correct 260 ms 18100 KB Output is correct
72 Correct 264 ms 18104 KB Output is correct
73 Correct 258 ms 18028 KB Output is correct
74 Correct 257 ms 18100 KB Output is correct
75 Correct 338 ms 27228 KB Output is correct
76 Correct 311 ms 27032 KB Output is correct
77 Correct 329 ms 29336 KB Output is correct
78 Correct 301 ms 29332 KB Output is correct
79 Correct 351 ms 26520 KB Output is correct
80 Correct 308 ms 29568 KB Output is correct
81 Correct 1536 ms 54860 KB Output is correct
82 Correct 1315 ms 54848 KB Output is correct
83 Correct 1387 ms 54672 KB Output is correct
84 Correct 1440 ms 55136 KB Output is correct
85 Correct 1376 ms 54868 KB Output is correct
86 Correct 1318 ms 54932 KB Output is correct
87 Correct 1665 ms 54572 KB Output is correct
88 Correct 1123 ms 36460 KB Output is correct
89 Correct 1134 ms 36372 KB Output is correct
90 Correct 1097 ms 36424 KB Output is correct
91 Correct 1088 ms 36340 KB Output is correct
92 Correct 1145 ms 36248 KB Output is correct
93 Correct 1210 ms 53736 KB Output is correct
94 Correct 1214 ms 54080 KB Output is correct
95 Correct 1279 ms 53772 KB Output is correct
96 Correct 1411 ms 53692 KB Output is correct
97 Correct 1622 ms 53848 KB Output is correct
98 Correct 797 ms 38036 KB Output is correct
99 Correct 1229 ms 53908 KB Output is correct
100 Correct 1180 ms 53672 KB Output is correct
101 Correct 1055 ms 43156 KB Output is correct
102 Correct 1233 ms 53124 KB Output is correct
103 Correct 1840 ms 52388 KB Output is correct
104 Correct 1115 ms 53852 KB Output is correct
105 Correct 922 ms 51612 KB Output is correct
106 Correct 920 ms 52372 KB Output is correct
107 Correct 921 ms 52488 KB Output is correct
108 Correct 911 ms 52628 KB Output is correct
109 Correct 867 ms 52628 KB Output is correct
110 Correct 875 ms 52600 KB Output is correct
111 Correct 895 ms 52376 KB Output is correct
112 Correct 914 ms 52632 KB Output is correct
113 Correct 941 ms 52632 KB Output is correct
114 Correct 901 ms 52476 KB Output is correct
115 Correct 918 ms 52616 KB Output is correct
116 Correct 890 ms 52512 KB Output is correct