#include <bits/stdc++.h>
#include <array>
#define all(v) (v.begin()), (v.end())
#define setall(a, val) for(auto& x : a) x = val
#define ll long long
clock_t start_time;
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
void init() {
#ifndef ONLINE_JUDGE
FILE* _ = freopen("in.txt", "r", stdin);
start_time = clock();
#endif
}
const ll MOD = 998244353;
const ll N = 6e5 + 1;
const ll M = 2e2 + 1;
using namespace std;
//####################################################################################
bool comp(array<ll, 4> a, array<ll, 4> b) {
if (a[0] == b[0])
return a[3] < b[3];
return a[0] > b[0];
}
bool comp2(array<ll, 4> a, array<ll, 4> b) {
return a[1] < b[1];
}
double dist(ll x1, ll y1, ll x2, ll y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); srand(time(0)); //init();
int n;
cin >> n;
vector< array<ll, 4> > v(n); // {radius, x, y, idx}
for (int i = 0; i < n; i++)
cin >> v[i][1] >> v[i][2] >> v[i][0], v[i][3] = i + 1;
sort(all(v), comp);
vector< array<ll, 4> > s = v;
map<int, int> m;
sort(all(s), comp2);
for (int i = 0; i < n; i++)
m[s[i][3]] = i;
vector<int> ans(n + 1, 0);
for (int i = 0; i < n; i++) {
if (ans[v[i][3]])
continue;
ans[v[i][3]] = v[i][3];
if (n <= 5000) {
for (int j = i + 1; j < n; j++) {
if (!ans[v[j][3]] && dist(v[i][1], v[i][2], v[j][1], v[j][2]) <= v[i][0] + v[j][0])
ans[v[j][3]] = v[i][3];
}
}
else {
for (int j = m[v[i][3]] + 1; j < n; j++) {
if (ans[s[j][3]] || s[j][1] - v[i][1] > v[i][0] + s[j][0])
continue;
ans[s[j][3]] = v[i][3];
}
for (int j = m[v[i][3]] - 1; j >= 0; j--) {
if (ans[s[j][3]] || v[i][1] - s[j][1] > v[i][0] + s[j][0])
continue;
ans[s[j][3]] = v[i][3];
}
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout << endl;
//cerr << get_time() << "s" << endl;
}
Compilation message
circle_selection.cpp: In function 'void init()':
circle_selection.cpp:10:8: warning: unused variable '_' [-Wunused-variable]
10 | FILE* _ = freopen("in.txt", "r", stdin);
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
1 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 |
4 ms |
980 KB |
Output is correct |
20 |
Correct |
4 ms |
852 KB |
Output is correct |
21 |
Correct |
4 ms |
852 KB |
Output is correct |
22 |
Correct |
46 ms |
880 KB |
Output is correct |
23 |
Correct |
42 ms |
852 KB |
Output is correct |
24 |
Correct |
45 ms |
892 KB |
Output is correct |
25 |
Correct |
50 ms |
904 KB |
Output is correct |
26 |
Correct |
44 ms |
892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
381 ms |
36380 KB |
Output is correct |
2 |
Correct |
339 ms |
36468 KB |
Output is correct |
3 |
Correct |
353 ms |
36176 KB |
Output is correct |
4 |
Correct |
352 ms |
36404 KB |
Output is correct |
5 |
Execution timed out |
3064 ms |
34272 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1390 ms |
12180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3081 ms |
34304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
1 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 |
4 ms |
980 KB |
Output is correct |
20 |
Correct |
4 ms |
852 KB |
Output is correct |
21 |
Correct |
4 ms |
852 KB |
Output is correct |
22 |
Correct |
46 ms |
880 KB |
Output is correct |
23 |
Correct |
42 ms |
852 KB |
Output is correct |
24 |
Correct |
45 ms |
892 KB |
Output is correct |
25 |
Correct |
50 ms |
904 KB |
Output is correct |
26 |
Correct |
44 ms |
892 KB |
Output is correct |
27 |
Incorrect |
12 ms |
1492 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 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 |
1 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 |
4 ms |
980 KB |
Output is correct |
20 |
Correct |
4 ms |
852 KB |
Output is correct |
21 |
Correct |
4 ms |
852 KB |
Output is correct |
22 |
Correct |
46 ms |
880 KB |
Output is correct |
23 |
Correct |
42 ms |
852 KB |
Output is correct |
24 |
Correct |
45 ms |
892 KB |
Output is correct |
25 |
Correct |
50 ms |
904 KB |
Output is correct |
26 |
Correct |
44 ms |
892 KB |
Output is correct |
27 |
Correct |
381 ms |
36380 KB |
Output is correct |
28 |
Correct |
339 ms |
36468 KB |
Output is correct |
29 |
Correct |
353 ms |
36176 KB |
Output is correct |
30 |
Correct |
352 ms |
36404 KB |
Output is correct |
31 |
Execution timed out |
3064 ms |
34272 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |