답안 #1075362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1075362 2024-08-26T04:24:22 Z ngrace 원 고르기 (APIO18_circle_selection) C++14
100 / 100
1830 ms 55056 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);

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

    for(int i:eBy) cout<<i+1<<" ";
    cout<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 516 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 7 ms 856 KB Output is correct
21 Correct 6 ms 860 KB Output is correct
22 Correct 13 ms 1240 KB Output is correct
23 Correct 14 ms 1236 KB Output is correct
24 Correct 14 ms 1332 KB Output is correct
25 Correct 12 ms 1184 KB Output is correct
26 Correct 13 ms 1288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 266 ms 26948 KB Output is correct
2 Correct 261 ms 24984 KB Output is correct
3 Correct 256 ms 23952 KB Output is correct
4 Correct 259 ms 27096 KB Output is correct
5 Correct 279 ms 22660 KB Output is correct
6 Correct 661 ms 32720 KB Output is correct
7 Correct 310 ms 24068 KB Output is correct
8 Correct 359 ms 26264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 390 ms 18608 KB Output is correct
3 Correct 1449 ms 54244 KB Output is correct
4 Correct 1430 ms 54368 KB Output is correct
5 Correct 1484 ms 48684 KB Output is correct
6 Correct 507 ms 24780 KB Output is correct
7 Correct 239 ms 13264 KB Output is correct
8 Correct 35 ms 3024 KB Output is correct
9 Correct 1547 ms 53608 KB Output is correct
10 Correct 1197 ms 46444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1180 ms 54684 KB Output is correct
2 Correct 975 ms 54096 KB Output is correct
3 Correct 495 ms 31552 KB Output is correct
4 Correct 1119 ms 54428 KB Output is correct
5 Correct 1104 ms 54428 KB Output is correct
6 Correct 359 ms 27032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 516 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 7 ms 856 KB Output is correct
21 Correct 6 ms 860 KB Output is correct
22 Correct 13 ms 1240 KB Output is correct
23 Correct 14 ms 1236 KB Output is correct
24 Correct 14 ms 1332 KB Output is correct
25 Correct 12 ms 1184 KB Output is correct
26 Correct 13 ms 1288 KB Output is correct
27 Correct 11 ms 1240 KB Output is correct
28 Correct 13 ms 1524 KB Output is correct
29 Correct 10 ms 1240 KB Output is correct
30 Correct 28 ms 2000 KB Output is correct
31 Correct 29 ms 2196 KB Output is correct
32 Correct 27 ms 2004 KB Output is correct
33 Correct 115 ms 9656 KB Output is correct
34 Correct 121 ms 9652 KB Output is correct
35 Correct 109 ms 9308 KB Output is correct
36 Correct 391 ms 18360 KB Output is correct
37 Correct 383 ms 18376 KB Output is correct
38 Correct 397 ms 18360 KB Output is correct
39 Correct 321 ms 12192 KB Output is correct
40 Correct 336 ms 12232 KB Output is correct
41 Correct 327 ms 12464 KB Output is correct
42 Correct 224 ms 13084 KB Output is correct
43 Correct 281 ms 18160 KB Output is correct
44 Correct 267 ms 18084 KB Output is correct
45 Correct 322 ms 18152 KB Output is correct
46 Correct 276 ms 18104 KB Output is correct
47 Correct 289 ms 18240 KB Output is correct
48 Correct 308 ms 18104 KB Output is correct
49 Correct 306 ms 18000 KB Output is correct
50 Correct 302 ms 18104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 600 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 516 KB Output is correct
19 Correct 5 ms 860 KB Output is correct
20 Correct 7 ms 856 KB Output is correct
21 Correct 6 ms 860 KB Output is correct
22 Correct 13 ms 1240 KB Output is correct
23 Correct 14 ms 1236 KB Output is correct
24 Correct 14 ms 1332 KB Output is correct
25 Correct 12 ms 1184 KB Output is correct
26 Correct 13 ms 1288 KB Output is correct
27 Correct 266 ms 26948 KB Output is correct
28 Correct 261 ms 24984 KB Output is correct
29 Correct 256 ms 23952 KB Output is correct
30 Correct 259 ms 27096 KB Output is correct
31 Correct 279 ms 22660 KB Output is correct
32 Correct 661 ms 32720 KB Output is correct
33 Correct 310 ms 24068 KB Output is correct
34 Correct 359 ms 26264 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 390 ms 18608 KB Output is correct
37 Correct 1449 ms 54244 KB Output is correct
38 Correct 1430 ms 54368 KB Output is correct
39 Correct 1484 ms 48684 KB Output is correct
40 Correct 507 ms 24780 KB Output is correct
41 Correct 239 ms 13264 KB Output is correct
42 Correct 35 ms 3024 KB Output is correct
43 Correct 1547 ms 53608 KB Output is correct
44 Correct 1197 ms 46444 KB Output is correct
45 Correct 1180 ms 54684 KB Output is correct
46 Correct 975 ms 54096 KB Output is correct
47 Correct 495 ms 31552 KB Output is correct
48 Correct 1119 ms 54428 KB Output is correct
49 Correct 1104 ms 54428 KB Output is correct
50 Correct 359 ms 27032 KB Output is correct
51 Correct 11 ms 1240 KB Output is correct
52 Correct 13 ms 1524 KB Output is correct
53 Correct 10 ms 1240 KB Output is correct
54 Correct 28 ms 2000 KB Output is correct
55 Correct 29 ms 2196 KB Output is correct
56 Correct 27 ms 2004 KB Output is correct
57 Correct 115 ms 9656 KB Output is correct
58 Correct 121 ms 9652 KB Output is correct
59 Correct 109 ms 9308 KB Output is correct
60 Correct 391 ms 18360 KB Output is correct
61 Correct 383 ms 18376 KB Output is correct
62 Correct 397 ms 18360 KB Output is correct
63 Correct 321 ms 12192 KB Output is correct
64 Correct 336 ms 12232 KB Output is correct
65 Correct 327 ms 12464 KB Output is correct
66 Correct 224 ms 13084 KB Output is correct
67 Correct 281 ms 18160 KB Output is correct
68 Correct 267 ms 18084 KB Output is correct
69 Correct 322 ms 18152 KB Output is correct
70 Correct 276 ms 18104 KB Output is correct
71 Correct 289 ms 18240 KB Output is correct
72 Correct 308 ms 18104 KB Output is correct
73 Correct 306 ms 18000 KB Output is correct
74 Correct 302 ms 18104 KB Output is correct
75 Correct 339 ms 27196 KB Output is correct
76 Correct 336 ms 26952 KB Output is correct
77 Correct 332 ms 29332 KB Output is correct
78 Correct 310 ms 29384 KB Output is correct
79 Correct 387 ms 26256 KB Output is correct
80 Correct 351 ms 29204 KB Output is correct
81 Correct 1767 ms 54752 KB Output is correct
82 Correct 1439 ms 54500 KB Output is correct
83 Correct 1638 ms 54504 KB Output is correct
84 Correct 1732 ms 55056 KB Output is correct
85 Correct 1605 ms 54584 KB Output is correct
86 Correct 1512 ms 54748 KB Output is correct
87 Correct 1830 ms 53920 KB Output is correct
88 Correct 1255 ms 36452 KB Output is correct
89 Correct 1120 ms 36248 KB Output is correct
90 Correct 1158 ms 36384 KB Output is correct
91 Correct 1121 ms 36476 KB Output is correct
92 Correct 1133 ms 36252 KB Output is correct
93 Correct 1180 ms 53400 KB Output is correct
94 Correct 1181 ms 53624 KB Output is correct
95 Correct 1239 ms 52236 KB Output is correct
96 Correct 1322 ms 52276 KB Output is correct
97 Correct 1537 ms 52212 KB Output is correct
98 Correct 751 ms 36508 KB Output is correct
99 Correct 1150 ms 52348 KB Output is correct
100 Correct 1106 ms 52212 KB Output is correct
101 Correct 994 ms 41688 KB Output is correct
102 Correct 1074 ms 51860 KB Output is correct
103 Correct 1624 ms 51000 KB Output is correct
104 Correct 1074 ms 52320 KB Output is correct
105 Correct 804 ms 38040 KB Output is correct
106 Correct 839 ms 50852 KB Output is correct
107 Correct 901 ms 50820 KB Output is correct
108 Correct 841 ms 51864 KB Output is correct
109 Correct 879 ms 51816 KB Output is correct
110 Correct 894 ms 51840 KB Output is correct
111 Correct 907 ms 51864 KB Output is correct
112 Correct 871 ms 51848 KB Output is correct
113 Correct 934 ms 51816 KB Output is correct
114 Correct 903 ms 51852 KB Output is correct
115 Correct 876 ms 51836 KB Output is correct
116 Correct 869 ms 51792 KB Output is correct