#include <bits/stdc++.h>
#define sz(v) v.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;
const int N = (int)3e5 + 7;
const int M = (int)15e6 + 7;
const ll MOD = (ll)1e9 + 7;
const int inf = (ll)1e9 + 7;
const ll INF = (ll)3e18 + 7;
pii dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int n, x[N], y[N], c[N], a[N];
bool used[N];
bool intersect(int i, int j) {
int d = c[i] + c[j];
d *= d;
int p = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
return p <= d;
}
bool ok() {
for(int i = 1; i <= n; ++i) if(!used[i]) return 0;
return 1;
}
void solve() {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> c[i];
if(n <= 5000) {
while(!ok()) {
int id = 0;
for(int i = 1; i <= n; ++i) if(!used[i] && c[i] > c[id]) id = i;
for(int i = 1; i <= n; ++i) {
if(!used[i] && intersect(i, id)) a[i] = id, used[i] = 1;
}
}
} else {
set<pii> s;
for(int i = 1; i <= n; ++i) s.insert({c[i], i});
while(!s.empty()) {
int i = (*s.rbegin()).y;
s.erase({c[i], i});
a[i] = i;
vector<pii> v;
for(auto [t, j] : s) {
if(intersect(i, j)) {
v.pb({t, j});
a[j] = i;
}
}
for(auto e : v) s.erase(e);
}
}
for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
for(int i = 1; i <= test; ++i) {
//cout << "Case " << i << ": ";
solve();
}
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
155 ms |
508 KB |
Output is correct |
23 |
Correct |
156 ms |
492 KB |
Output is correct |
24 |
Correct |
158 ms |
496 KB |
Output is correct |
25 |
Correct |
150 ms |
496 KB |
Output is correct |
26 |
Correct |
156 ms |
496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
383 ms |
36784 KB |
Output is correct |
2 |
Correct |
395 ms |
34880 KB |
Output is correct |
3 |
Correct |
364 ms |
32636 KB |
Output is correct |
4 |
Correct |
357 ms |
36756 KB |
Output is correct |
5 |
Execution timed out |
3083 ms |
28572 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3072 ms |
9820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3064 ms |
26124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
155 ms |
508 KB |
Output is correct |
23 |
Correct |
156 ms |
492 KB |
Output is correct |
24 |
Correct |
158 ms |
496 KB |
Output is correct |
25 |
Correct |
150 ms |
496 KB |
Output is correct |
26 |
Correct |
156 ms |
496 KB |
Output is correct |
27 |
Correct |
6 ms |
1612 KB |
Output is correct |
28 |
Correct |
9 ms |
1612 KB |
Output is correct |
29 |
Correct |
7 ms |
1612 KB |
Output is correct |
30 |
Correct |
999 ms |
1276 KB |
Output is correct |
31 |
Correct |
1138 ms |
1276 KB |
Output is correct |
32 |
Correct |
1152 ms |
1320 KB |
Output is correct |
33 |
Correct |
82 ms |
11832 KB |
Output is correct |
34 |
Correct |
115 ms |
11836 KB |
Output is correct |
35 |
Correct |
100 ms |
11832 KB |
Output is correct |
36 |
Execution timed out |
3070 ms |
9504 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
460 KB |
Output is correct |
20 |
Correct |
3 ms |
460 KB |
Output is correct |
21 |
Correct |
3 ms |
460 KB |
Output is correct |
22 |
Correct |
155 ms |
508 KB |
Output is correct |
23 |
Correct |
156 ms |
492 KB |
Output is correct |
24 |
Correct |
158 ms |
496 KB |
Output is correct |
25 |
Correct |
150 ms |
496 KB |
Output is correct |
26 |
Correct |
156 ms |
496 KB |
Output is correct |
27 |
Correct |
383 ms |
36784 KB |
Output is correct |
28 |
Correct |
395 ms |
34880 KB |
Output is correct |
29 |
Correct |
364 ms |
32636 KB |
Output is correct |
30 |
Correct |
357 ms |
36756 KB |
Output is correct |
31 |
Execution timed out |
3083 ms |
28572 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |