Submission #698682

# Submission time Handle Problem Language Result Execution time Memory
698682 2023-02-14T07:37:35 Z vjudge1 Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 26664 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=3;
            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]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 5 ms 680 KB Output is correct
22 Correct 10 ms 788 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 788 KB Output is correct
26 Correct 10 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 17132 KB Output is correct
2 Correct 232 ms 17248 KB Output is correct
3 Correct 221 ms 17132 KB Output is correct
4 Correct 221 ms 17144 KB Output is correct
5 Correct 223 ms 17148 KB Output is correct
6 Correct 420 ms 17880 KB Output is correct
7 Correct 236 ms 17088 KB Output is correct
8 Correct 262 ms 17200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 312 ms 7076 KB Output is correct
3 Correct 1086 ms 23308 KB Output is correct
4 Correct 1038 ms 23380 KB Output is correct
5 Correct 905 ms 18916 KB Output is correct
6 Correct 380 ms 12108 KB Output is correct
7 Correct 164 ms 6340 KB Output is correct
8 Correct 24 ms 1488 KB Output is correct
9 Correct 1049 ms 23316 KB Output is correct
10 Correct 850 ms 19004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 936 ms 23240 KB Output is correct
2 Correct 845 ms 23244 KB Output is correct
3 Correct 347 ms 17084 KB Output is correct
4 Correct 832 ms 23324 KB Output is correct
5 Correct 840 ms 23248 KB Output is correct
6 Correct 312 ms 17120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 5 ms 680 KB Output is correct
22 Correct 10 ms 788 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 788 KB Output is correct
26 Correct 10 ms 772 KB Output is correct
27 Correct 7 ms 980 KB Output is correct
28 Correct 6 ms 980 KB Output is correct
29 Correct 7 ms 980 KB Output is correct
30 Correct 22 ms 1212 KB Output is correct
31 Correct 24 ms 1212 KB Output is correct
32 Correct 20 ms 1172 KB Output is correct
33 Correct 72 ms 5704 KB Output is correct
34 Correct 68 ms 5740 KB Output is correct
35 Correct 71 ms 5676 KB Output is correct
36 Correct 264 ms 6964 KB Output is correct
37 Correct 275 ms 6960 KB Output is correct
38 Correct 272 ms 6952 KB Output is correct
39 Correct 204 ms 6992 KB Output is correct
40 Correct 202 ms 6980 KB Output is correct
41 Correct 206 ms 6944 KB Output is correct
42 Correct 161 ms 7048 KB Output is correct
43 Correct 235 ms 7012 KB Output is correct
44 Correct 236 ms 7036 KB Output is correct
45 Correct 237 ms 6968 KB Output is correct
46 Correct 224 ms 6988 KB Output is correct
47 Correct 225 ms 7060 KB Output is correct
48 Correct 226 ms 6972 KB Output is correct
49 Correct 230 ms 7000 KB Output is correct
50 Correct 221 ms 7016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 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 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 5 ms 680 KB Output is correct
22 Correct 10 ms 788 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 788 KB Output is correct
26 Correct 10 ms 772 KB Output is correct
27 Correct 221 ms 17132 KB Output is correct
28 Correct 232 ms 17248 KB Output is correct
29 Correct 221 ms 17132 KB Output is correct
30 Correct 221 ms 17144 KB Output is correct
31 Correct 223 ms 17148 KB Output is correct
32 Correct 420 ms 17880 KB Output is correct
33 Correct 236 ms 17088 KB Output is correct
34 Correct 262 ms 17200 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 312 ms 7076 KB Output is correct
37 Correct 1086 ms 23308 KB Output is correct
38 Correct 1038 ms 23380 KB Output is correct
39 Correct 905 ms 18916 KB Output is correct
40 Correct 380 ms 12108 KB Output is correct
41 Correct 164 ms 6340 KB Output is correct
42 Correct 24 ms 1488 KB Output is correct
43 Correct 1049 ms 23316 KB Output is correct
44 Correct 850 ms 19004 KB Output is correct
45 Correct 936 ms 23240 KB Output is correct
46 Correct 845 ms 23244 KB Output is correct
47 Correct 347 ms 17084 KB Output is correct
48 Correct 832 ms 23324 KB Output is correct
49 Correct 840 ms 23248 KB Output is correct
50 Correct 312 ms 17120 KB Output is correct
51 Correct 7 ms 980 KB Output is correct
52 Correct 6 ms 980 KB Output is correct
53 Correct 7 ms 980 KB Output is correct
54 Correct 22 ms 1212 KB Output is correct
55 Correct 24 ms 1212 KB Output is correct
56 Correct 20 ms 1172 KB Output is correct
57 Correct 72 ms 5704 KB Output is correct
58 Correct 68 ms 5740 KB Output is correct
59 Correct 71 ms 5676 KB Output is correct
60 Correct 264 ms 6964 KB Output is correct
61 Correct 275 ms 6960 KB Output is correct
62 Correct 272 ms 6952 KB Output is correct
63 Correct 204 ms 6992 KB Output is correct
64 Correct 202 ms 6980 KB Output is correct
65 Correct 206 ms 6944 KB Output is correct
66 Correct 161 ms 7048 KB Output is correct
67 Correct 235 ms 7012 KB Output is correct
68 Correct 236 ms 7036 KB Output is correct
69 Correct 237 ms 6968 KB Output is correct
70 Correct 224 ms 6988 KB Output is correct
71 Correct 225 ms 7060 KB Output is correct
72 Correct 226 ms 6972 KB Output is correct
73 Correct 230 ms 7000 KB Output is correct
74 Correct 221 ms 7016 KB Output is correct
75 Correct 242 ms 17140 KB Output is correct
76 Correct 216 ms 17148 KB Output is correct
77 Correct 219 ms 17132 KB Output is correct
78 Correct 212 ms 17132 KB Output is correct
79 Correct 293 ms 17064 KB Output is correct
80 Correct 217 ms 17104 KB Output is correct
81 Correct 1048 ms 23340 KB Output is correct
82 Correct 1000 ms 23268 KB Output is correct
83 Correct 996 ms 23244 KB Output is correct
84 Correct 1108 ms 23244 KB Output is correct
85 Correct 1016 ms 23512 KB Output is correct
86 Correct 1032 ms 23328 KB Output is correct
87 Correct 1298 ms 23216 KB Output is correct
88 Correct 678 ms 18200 KB Output is correct
89 Correct 679 ms 18096 KB Output is correct
90 Correct 685 ms 18168 KB Output is correct
91 Correct 679 ms 18108 KB Output is correct
92 Correct 692 ms 18056 KB Output is correct
93 Correct 872 ms 23212 KB Output is correct
94 Execution timed out 3062 ms 26664 KB Time limit exceeded
95 Halted 0 ms 0 KB -