#include "bits/stdc++.h"
#define ll long long
#define pb push_back
#define endl '\n'
#define fi first
#define sec second
using namespace std;
ll dis(pair<ll,ll>p1,pair<ll,ll>p2)
{
ll a=(p1.first-p2.first) , b=(p1.second-p2.second);
return (a*a)+(b*b);
}
bool sorting1 (pair<ll,ll>a,pair<ll,ll>b)
{
if(a.first!=b.first)
return (a.first>b.first);
return (a.second<b.second);
}
bool sorting2 (pair<pair<ll,ll>,pair<ll,ll>>a,pair<pair<ll,ll>,pair<ll,ll>>b)
{
if(a.fi.fi!=b.fi.fi)
return (a.fi.fi>b.fi.fi);
return (a.sec.sec<b.sec.sec);
}
signed main () {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
bool m=1;
vector<pair<ll,pair<ll,ll>>>inp(n);
for(int i=0;i<n;i++)
{
ll x,y,z;
cin>>x>>y>>z;
if(y)m=0;
inp[i]={x,{y,z}};
}
if(!m)
{
vector<pair<ll,ll>>v,c;
for(int i=0;i<n;i++)
{
ll x=inp[i].fi,y=inp[i].sec.fi,r=inp[i].sec.sec;
c.pb({x,y});
v.pb({r,i});
}
sort(v.begin(),v.end(),sorting1);
ll ans[n]={};
for(int i=0;i<n;i++)
{
if(ans[v[i].second])continue;
for(int j=i;j<n;j++)
{
if(ans[v[j].second])continue;
if(dis(c[v[i].second],c[v[j].second])<=((v[i].first+v[j].first)*(v[i].first+v[j].first)) )
ans[v[j].second]=v[i].second+1;
}
}
for(int i=0;i<n;i++)
cout<<ans[i]<<' ';
}
else
{
vector<pair<pair<ll,ll>,pair<ll,ll>>>v,c;
for(int i=0;i<n;i++)
{
ll x=inp[i].fi,y=inp[i].sec.fi,r=inp[i].sec.sec;
c.pb({{x-r,x+r},{r,i}});
v.pb({{r,i},{x-r,x+r}});
}
sort(v.begin(),v.end(),sorting2);
sort(c.begin(),c.end());
ll ans[n]={};
for(int i=0;i<n;i++)
{
if(ans[v[i].fi.sec])continue;
//cout<<v[i].fi.fi<<endl;
swap(v[i].sec,v[i].fi);
auto u=lower_bound(c.begin(),c.end(),v[i]);
for(ll j=u-c.begin();j<n;j++)
{
//cout<<' '<<j<<' '<<v[i].fi.sec<<' '<<c[j].fi.fi<<endl;
if(v[i].fi.sec<c[j].fi.fi)break;
if(ans[c[j].sec.sec])continue;
ans[c[j].sec.sec]=v[i].sec.sec+1;
}
}
for(int i=0;i<n;i++)
cout<<ans[i]<<' ';
}
return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
4
0 0 4
1 0 1
2 0 3
7 0 1
-1 1 1 4
4
0 0 1
2 0 1
4 0 1
6 0 1
- 1 1 3 3
*/
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:76:22: warning: unused variable 'y' [-Wunused-variable]
76 | ll x=inp[i].fi,y=inp[i].sec.fi,r=inp[i].sec.sec;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 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 |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
31 ms |
768 KB |
Output is correct |
23 |
Correct |
30 ms |
724 KB |
Output is correct |
24 |
Correct |
32 ms |
776 KB |
Output is correct |
25 |
Correct |
29 ms |
724 KB |
Output is correct |
26 |
Correct |
29 ms |
780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
202 ms |
32160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
3077 ms |
6728 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3058 ms |
19880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 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 |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
31 ms |
768 KB |
Output is correct |
23 |
Correct |
30 ms |
724 KB |
Output is correct |
24 |
Correct |
32 ms |
776 KB |
Output is correct |
25 |
Correct |
29 ms |
724 KB |
Output is correct |
26 |
Correct |
29 ms |
780 KB |
Output is correct |
27 |
Correct |
5 ms |
1232 KB |
Output is correct |
28 |
Correct |
5 ms |
1232 KB |
Output is correct |
29 |
Correct |
5 ms |
1104 KB |
Output is correct |
30 |
Correct |
133 ms |
1160 KB |
Output is correct |
31 |
Correct |
133 ms |
1164 KB |
Output is correct |
32 |
Correct |
126 ms |
1156 KB |
Output is correct |
33 |
Correct |
52 ms |
7384 KB |
Output is correct |
34 |
Correct |
50 ms |
7380 KB |
Output is correct |
35 |
Correct |
52 ms |
7316 KB |
Output is correct |
36 |
Execution timed out |
3078 ms |
6672 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 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 |
2 ms |
724 KB |
Output is correct |
20 |
Correct |
3 ms |
724 KB |
Output is correct |
21 |
Correct |
3 ms |
724 KB |
Output is correct |
22 |
Correct |
31 ms |
768 KB |
Output is correct |
23 |
Correct |
30 ms |
724 KB |
Output is correct |
24 |
Correct |
32 ms |
776 KB |
Output is correct |
25 |
Correct |
29 ms |
724 KB |
Output is correct |
26 |
Correct |
29 ms |
780 KB |
Output is correct |
27 |
Incorrect |
202 ms |
32160 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |