#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e18, N = 3e5 + 5;
vector<int> g[N];
bool vis[N];
bool cmp(array<int, 2> a, array<int, 2> b)
{
if(a[0] != b[0])
{
return a[0] > b[0];
}
return a[1] < b[1];
}
void Solve()
{
int n;
cin >> n;
vector<array<int, 3> > circle(n + 1);
for(int i = 1; i <= n; i++)
{
cin >> circle[i][0] >> circle[i][1] >> circle[i][2];
}
vector<array<int, 2> > order;
for(int i = 1; i <= n; i++)
{
order.push_back({circle[i][2], i});
for(int j = i + 1; j <= n; j++)
{
int x = abs(circle[i][0] - circle[j][0]), y = abs(circle[i][1] - circle[j][1]);
int dist = x * x + y * y;
if(dist <= (circle[i][2] + circle[j][2]) * (circle[i][2] + circle[j][2]))
{
g[i].push_back(j);
g[j].push_back(i);
}
}
}
sort(order.begin(), order.end(), cmp);
vector<int> res(n + 1, -1);
for(int i = 0; i < order.size(); i++)
{
int idx = order[i][1];
if(vis[idx]) continue;
vis[idx] = true;
res[idx] = idx;
for(int j: g[idx])
{
if(!vis[j])
{
vis[j] = true;
res[j] = idx;
}
}
}
// cout << "omk\n";
for(int i = 1; i <= n; i++)
{
cout << res[i] << " ";
}
cout << "\n";
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
//cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
/*
Sample 1:
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
*/
Compilation message
circle_selection.cpp: In function 'void Solve()':
circle_selection.cpp:46:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0; i < order.size(); i++)
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7504 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7380 KB |
Output is correct |
11 |
Correct |
5 ms |
7504 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7372 KB |
Output is correct |
16 |
Correct |
15 ms |
15824 KB |
Output is correct |
17 |
Correct |
15 ms |
15376 KB |
Output is correct |
18 |
Correct |
16 ms |
16124 KB |
Output is correct |
19 |
Correct |
282 ms |
261816 KB |
Output is correct |
20 |
Correct |
274 ms |
262476 KB |
Output is correct |
21 |
Correct |
239 ms |
164772 KB |
Output is correct |
22 |
Correct |
46 ms |
7772 KB |
Output is correct |
23 |
Correct |
47 ms |
7756 KB |
Output is correct |
24 |
Correct |
45 ms |
7836 KB |
Output is correct |
25 |
Correct |
45 ms |
7752 KB |
Output is correct |
26 |
Correct |
45 ms |
7756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2238 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Execution timed out |
3041 ms |
11500 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
14600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7504 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7380 KB |
Output is correct |
11 |
Correct |
5 ms |
7504 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7372 KB |
Output is correct |
16 |
Correct |
15 ms |
15824 KB |
Output is correct |
17 |
Correct |
15 ms |
15376 KB |
Output is correct |
18 |
Correct |
16 ms |
16124 KB |
Output is correct |
19 |
Correct |
282 ms |
261816 KB |
Output is correct |
20 |
Correct |
274 ms |
262476 KB |
Output is correct |
21 |
Correct |
239 ms |
164772 KB |
Output is correct |
22 |
Correct |
46 ms |
7772 KB |
Output is correct |
23 |
Correct |
47 ms |
7756 KB |
Output is correct |
24 |
Correct |
45 ms |
7836 KB |
Output is correct |
25 |
Correct |
45 ms |
7752 KB |
Output is correct |
26 |
Correct |
45 ms |
7756 KB |
Output is correct |
27 |
Correct |
1067 ms |
736332 KB |
Output is correct |
28 |
Correct |
1179 ms |
909512 KB |
Output is correct |
29 |
Correct |
1169 ms |
876488 KB |
Output is correct |
30 |
Correct |
162 ms |
8244 KB |
Output is correct |
31 |
Correct |
161 ms |
8268 KB |
Output is correct |
32 |
Correct |
162 ms |
8288 KB |
Output is correct |
33 |
Runtime error |
1883 ms |
1048576 KB |
Execution killed with signal 9 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7504 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7380 KB |
Output is correct |
11 |
Correct |
5 ms |
7504 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7372 KB |
Output is correct |
16 |
Correct |
15 ms |
15824 KB |
Output is correct |
17 |
Correct |
15 ms |
15376 KB |
Output is correct |
18 |
Correct |
16 ms |
16124 KB |
Output is correct |
19 |
Correct |
282 ms |
261816 KB |
Output is correct |
20 |
Correct |
274 ms |
262476 KB |
Output is correct |
21 |
Correct |
239 ms |
164772 KB |
Output is correct |
22 |
Correct |
46 ms |
7772 KB |
Output is correct |
23 |
Correct |
47 ms |
7756 KB |
Output is correct |
24 |
Correct |
45 ms |
7836 KB |
Output is correct |
25 |
Correct |
45 ms |
7752 KB |
Output is correct |
26 |
Correct |
45 ms |
7756 KB |
Output is correct |
27 |
Runtime error |
2238 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Halted |
0 ms |
0 KB |
- |