#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 |
1 ms |
284 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 |
0 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 |
0 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 |
28 ms |
780 KB |
Output is correct |
23 |
Correct |
32 ms |
848 KB |
Output is correct |
24 |
Correct |
29 ms |
780 KB |
Output is correct |
25 |
Correct |
30 ms |
772 KB |
Output is correct |
26 |
Correct |
29 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
197 ms |
32148 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 |
3072 ms |
6736 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 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 |
1 ms |
284 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 |
0 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 |
0 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 |
28 ms |
780 KB |
Output is correct |
23 |
Correct |
32 ms |
848 KB |
Output is correct |
24 |
Correct |
29 ms |
780 KB |
Output is correct |
25 |
Correct |
30 ms |
772 KB |
Output is correct |
26 |
Correct |
29 ms |
776 KB |
Output is correct |
27 |
Correct |
5 ms |
1232 KB |
Output is correct |
28 |
Correct |
5 ms |
1228 KB |
Output is correct |
29 |
Correct |
5 ms |
1104 KB |
Output is correct |
30 |
Correct |
113 ms |
1196 KB |
Output is correct |
31 |
Correct |
118 ms |
1164 KB |
Output is correct |
32 |
Correct |
117 ms |
1172 KB |
Output is correct |
33 |
Correct |
51 ms |
7364 KB |
Output is correct |
34 |
Correct |
48 ms |
7348 KB |
Output is correct |
35 |
Correct |
50 ms |
7372 KB |
Output is correct |
36 |
Execution timed out |
3080 ms |
6704 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 |
1 ms |
284 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 |
0 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 |
0 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 |
28 ms |
780 KB |
Output is correct |
23 |
Correct |
32 ms |
848 KB |
Output is correct |
24 |
Correct |
29 ms |
780 KB |
Output is correct |
25 |
Correct |
30 ms |
772 KB |
Output is correct |
26 |
Correct |
29 ms |
776 KB |
Output is correct |
27 |
Incorrect |
197 ms |
32148 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |