답안 #698879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698879 2023-02-14T14:48:14 Z milisav 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 31984 KB
#include<bits/stdc++.h>
#define maxn 400000
using namespace std;
int n;
int el[maxn];
int x[maxn];
int y[maxn];
int rev[maxn];
int radius[maxn];
pair<pair<int,int>,pair<int,int> > circ[maxn];
vector<pair<pair<int,int>,int> > v;
set<pair<int,int> > s;
inline bool intersect(int i,int j) {
    return 1ll*(x[i]-x[j])*(x[i]-x[j])+1ll*(y[i]-y[j])*(y[i]-y[j])<=1ll*(radius[i]+radius[j])*(radius[i]+radius[j]);
}
void dc(int l,int r) {
    if(l==r) return;
    int m=(l+r)/2;
    dc(l,m);
    //cout<<l<<" "<<m<<" "<<r<<endl;
    for(int i=l;i<=r;i++) {
        int ind=circ[i].first.second;
        if(el[ind]==ind) {
            //cout<<ind<<endl;
            if(i<=m) {
                v.push_back({{x[ind]-radius[ind],0},ind});
                v.push_back({{x[ind]+radius[ind],2},ind});
            }
            else {
                v.push_back({{x[ind]-radius[ind],1},ind});
                v.push_back({{x[ind]+radius[ind],1},ind});
            }
        }
    }
    sort(v.begin(),v.end());
    for(auto p:v) {
        int xc=p.first.first;
        int ind=p.second;
        int pos=rev[ind];
        if(pos<=m) {
            //cout<<ind<<" "<<pos<<endl;
            if(xc == x[ind]-radius[ind]) s.insert({y[ind],ind});
            else s.erase({y[ind],ind});
        }
        else {
            if(s.empty()) continue;
            set<pair<int,int> >::iterator it=s.lower_bound({y[ind],-1});
            set<pair<int,int> >::iterator st=it;
            int co=1;
            int i=0;
            //cout<<ind<<" "<<pos<<endl;
            while(it!=s.end() && i<=co) {
                int jnd=(*it).second;
                if(rev[jnd]<rev[el[ind]] && intersect(ind,jnd)) {
                    el[ind]=jnd;
                }
                it++;
                i++;
            }
            it=st;
            if(it==s.begin()) continue;
            i=0;
            do {
                it--;
                int jnd=(*it).second;
                if(rev[jnd]<rev[el[ind]] && intersect(ind,jnd)) {
                    el[ind]=jnd;
                }
                i++;
            } while(it!=s.begin() && i<=co);
        }
    }
    s.clear();
    v.clear();
    dc(m+1,r);
}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d %d %d",&x[i],&y[i],&radius[i]);
        circ[i]={{-radius[i],i},{x[i],y[i]}};
        el[i]=i;
    }
    sort(circ+1,circ+n+1);
    for(int i=1;i<=n;i++) {
        rev[circ[i].first.second]=i;
        //cout<<circ[i].first.second<<" ";
    }
    //cout<<endl;
    dc(1,n);
    for(int i=1;i<=n;i++) {
        printf("%d ",el[i]);
    }
    printf("\n");
    return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
circle_selection.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         scanf("%d %d %d",&x[i],&y[i],&radius[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 12 ms 804 KB Output is correct
23 Correct 12 ms 792 KB Output is correct
24 Correct 10 ms 788 KB Output is correct
25 Correct 9 ms 800 KB Output is correct
26 Correct 10 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 17056 KB Output is correct
2 Correct 253 ms 17144 KB Output is correct
3 Correct 215 ms 17176 KB Output is correct
4 Correct 221 ms 17140 KB Output is correct
5 Correct 229 ms 17068 KB Output is correct
6 Correct 425 ms 18900 KB Output is correct
7 Correct 240 ms 18176 KB Output is correct
8 Correct 261 ms 18156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 299 ms 7012 KB Output is correct
3 Correct 1045 ms 28564 KB Output is correct
4 Correct 1087 ms 28660 KB Output is correct
5 Correct 861 ms 24016 KB Output is correct
6 Correct 338 ms 16428 KB Output is correct
7 Correct 169 ms 8660 KB Output is correct
8 Correct 30 ms 1864 KB Output is correct
9 Correct 1022 ms 28624 KB Output is correct
10 Correct 856 ms 24300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 941 ms 23308 KB Output is correct
2 Correct 864 ms 28528 KB Output is correct
3 Correct 323 ms 22520 KB Output is correct
4 Correct 891 ms 28544 KB Output is correct
5 Correct 881 ms 28624 KB Output is correct
6 Correct 292 ms 22228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 12 ms 804 KB Output is correct
23 Correct 12 ms 792 KB Output is correct
24 Correct 10 ms 788 KB Output is correct
25 Correct 9 ms 800 KB Output is correct
26 Correct 10 ms 776 KB Output is correct
27 Correct 9 ms 980 KB Output is correct
28 Correct 9 ms 980 KB Output is correct
29 Correct 9 ms 980 KB Output is correct
30 Correct 23 ms 1212 KB Output is correct
31 Correct 21 ms 1176 KB Output is correct
32 Correct 21 ms 1168 KB Output is correct
33 Correct 71 ms 5748 KB Output is correct
34 Correct 76 ms 5900 KB Output is correct
35 Correct 71 ms 5720 KB Output is correct
36 Correct 309 ms 6948 KB Output is correct
37 Correct 277 ms 9668 KB Output is correct
38 Correct 297 ms 9692 KB Output is correct
39 Correct 188 ms 8036 KB Output is correct
40 Correct 209 ms 8136 KB Output is correct
41 Correct 208 ms 8116 KB Output is correct
42 Correct 144 ms 8664 KB Output is correct
43 Correct 260 ms 9732 KB Output is correct
44 Correct 232 ms 9640 KB Output is correct
45 Correct 243 ms 9660 KB Output is correct
46 Correct 262 ms 9680 KB Output is correct
47 Correct 261 ms 9568 KB Output is correct
48 Correct 249 ms 9672 KB Output is correct
49 Correct 244 ms 9584 KB Output is correct
50 Correct 236 ms 9672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 12 ms 804 KB Output is correct
23 Correct 12 ms 792 KB Output is correct
24 Correct 10 ms 788 KB Output is correct
25 Correct 9 ms 800 KB Output is correct
26 Correct 10 ms 776 KB Output is correct
27 Correct 214 ms 17056 KB Output is correct
28 Correct 253 ms 17144 KB Output is correct
29 Correct 215 ms 17176 KB Output is correct
30 Correct 221 ms 17140 KB Output is correct
31 Correct 229 ms 17068 KB Output is correct
32 Correct 425 ms 18900 KB Output is correct
33 Correct 240 ms 18176 KB Output is correct
34 Correct 261 ms 18156 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 299 ms 7012 KB Output is correct
37 Correct 1045 ms 28564 KB Output is correct
38 Correct 1087 ms 28660 KB Output is correct
39 Correct 861 ms 24016 KB Output is correct
40 Correct 338 ms 16428 KB Output is correct
41 Correct 169 ms 8660 KB Output is correct
42 Correct 30 ms 1864 KB Output is correct
43 Correct 1022 ms 28624 KB Output is correct
44 Correct 856 ms 24300 KB Output is correct
45 Correct 941 ms 23308 KB Output is correct
46 Correct 864 ms 28528 KB Output is correct
47 Correct 323 ms 22520 KB Output is correct
48 Correct 891 ms 28544 KB Output is correct
49 Correct 881 ms 28624 KB Output is correct
50 Correct 292 ms 22228 KB Output is correct
51 Correct 9 ms 980 KB Output is correct
52 Correct 9 ms 980 KB Output is correct
53 Correct 9 ms 980 KB Output is correct
54 Correct 23 ms 1212 KB Output is correct
55 Correct 21 ms 1176 KB Output is correct
56 Correct 21 ms 1168 KB Output is correct
57 Correct 71 ms 5748 KB Output is correct
58 Correct 76 ms 5900 KB Output is correct
59 Correct 71 ms 5720 KB Output is correct
60 Correct 309 ms 6948 KB Output is correct
61 Correct 277 ms 9668 KB Output is correct
62 Correct 297 ms 9692 KB Output is correct
63 Correct 188 ms 8036 KB Output is correct
64 Correct 209 ms 8136 KB Output is correct
65 Correct 208 ms 8116 KB Output is correct
66 Correct 144 ms 8664 KB Output is correct
67 Correct 260 ms 9732 KB Output is correct
68 Correct 232 ms 9640 KB Output is correct
69 Correct 243 ms 9660 KB Output is correct
70 Correct 262 ms 9680 KB Output is correct
71 Correct 261 ms 9568 KB Output is correct
72 Correct 249 ms 9672 KB Output is correct
73 Correct 244 ms 9584 KB Output is correct
74 Correct 236 ms 9672 KB Output is correct
75 Correct 272 ms 22372 KB Output is correct
76 Correct 229 ms 22368 KB Output is correct
77 Correct 243 ms 22292 KB Output is correct
78 Correct 232 ms 22324 KB Output is correct
79 Correct 267 ms 22264 KB Output is correct
80 Correct 227 ms 22308 KB Output is correct
81 Correct 1030 ms 28536 KB Output is correct
82 Correct 998 ms 28484 KB Output is correct
83 Correct 1031 ms 28524 KB Output is correct
84 Correct 1083 ms 28548 KB Output is correct
85 Correct 1020 ms 28560 KB Output is correct
86 Correct 972 ms 28560 KB Output is correct
87 Correct 1235 ms 28524 KB Output is correct
88 Correct 662 ms 21436 KB Output is correct
89 Correct 644 ms 21472 KB Output is correct
90 Correct 707 ms 21468 KB Output is correct
91 Correct 672 ms 21356 KB Output is correct
92 Correct 657 ms 21424 KB Output is correct
93 Correct 933 ms 28620 KB Output is correct
94 Execution timed out 3022 ms 31984 KB Time limit exceeded
95 Halted 0 ms 0 KB -