#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ari2=array<int,2>;
using ari3=array<int,3>;
#define vt vector
#define size(x) (int((x).size()))
#define all(x) begin(x), end(x)
#define REP(a,b,c,d) for (int a=(b);(d)>0?a<=(c):a>=(c);a+=(d))
#define FOR(a,b,c) REP(a,b,c,1)
#define ROF(a,b,c) REP(a,b,c,-1)
signed main() {
#ifndef DEBUG
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int N;
cin >> N;
vt<int> X(N), Y(N), R(N);
FOR(i, 0, N-1)
cin >> X[i] >> Y[i] >> R[i];
vt<int> ord(N);
iota(all(ord), 0);
sort(all(ord), [&](const int &a, const int &b) {
return ari2{R[a], b} > ari2{R[b], a};
});
auto good = [&](int i, int j) {
auto sq = [&](int x) {
return 1ll * x * x;
};
return sq(X[i]-X[j]) + sq(Y[i]-Y[j]) <= sq(R[i]+R[j]);
};
vt<int> ans(N, -1);
for (int r=1<<30; r>0; r>>=1) {
vt<ari3> points;
FOR(i, 0, N-1)
if (ans[i] < 0)
points.push_back({X[i]/r, Y[i]/r, i});
sort(all(points));
for (int i : ord) {
if (ans[i] >= 0 || R[i] < r/2 || R[i] > r)
continue;
#ifdef DEBUG
cout << "trying circle " << i+1 << " with r = " << r << '\n';
#endif
ans[i] = i;
int x = X[i] / r;
int y = Y[i] / r;
FOR(d, -2, 2)
FOR(j, lower_bound(all(points), ari3{x+d, y-2, 0}) - begin(points), size(points)-1) {
auto [xj, yj, ij] = points[j];
if (xj != x+d || abs(yj-y) > 2)
break;
#ifdef DEBUG
cout << "does circle " << ij+1 << " work\n";
#endif
if (good(i, ij) && ans[ij] < 0)
ans[ij] = i;
}
}
}
for (int &i : ans)
cout << i+1 << ' ';
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |
21 |
Correct |
3 ms |
688 KB |
Output is correct |
22 |
Correct |
13 ms |
840 KB |
Output is correct |
23 |
Correct |
15 ms |
836 KB |
Output is correct |
24 |
Correct |
12 ms |
836 KB |
Output is correct |
25 |
Correct |
16 ms |
832 KB |
Output is correct |
26 |
Correct |
13 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
22528 KB |
Output is correct |
2 |
Correct |
234 ms |
22684 KB |
Output is correct |
3 |
Correct |
221 ms |
22524 KB |
Output is correct |
4 |
Correct |
164 ms |
19140 KB |
Output is correct |
5 |
Correct |
1044 ms |
20776 KB |
Output is correct |
6 |
Correct |
1142 ms |
20932 KB |
Output is correct |
7 |
Correct |
1070 ms |
20960 KB |
Output is correct |
8 |
Correct |
1115 ms |
20808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
292 ms |
7884 KB |
Output is correct |
3 |
Correct |
994 ms |
24128 KB |
Output is correct |
4 |
Correct |
1006 ms |
24268 KB |
Output is correct |
5 |
Correct |
924 ms |
23880 KB |
Output is correct |
6 |
Correct |
429 ms |
12728 KB |
Output is correct |
7 |
Correct |
215 ms |
7072 KB |
Output is correct |
8 |
Correct |
41 ms |
1836 KB |
Output is correct |
9 |
Correct |
1020 ms |
24272 KB |
Output is correct |
10 |
Correct |
832 ms |
24632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1049 ms |
23904 KB |
Output is correct |
2 |
Correct |
1419 ms |
23104 KB |
Output is correct |
3 |
Correct |
568 ms |
24428 KB |
Output is correct |
4 |
Correct |
1188 ms |
23404 KB |
Output is correct |
5 |
Correct |
1188 ms |
23804 KB |
Output is correct |
6 |
Correct |
503 ms |
24708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |
21 |
Correct |
3 ms |
688 KB |
Output is correct |
22 |
Correct |
13 ms |
840 KB |
Output is correct |
23 |
Correct |
15 ms |
836 KB |
Output is correct |
24 |
Correct |
12 ms |
836 KB |
Output is correct |
25 |
Correct |
16 ms |
832 KB |
Output is correct |
26 |
Correct |
13 ms |
1092 KB |
Output is correct |
27 |
Correct |
6 ms |
1188 KB |
Output is correct |
28 |
Correct |
7 ms |
1260 KB |
Output is correct |
29 |
Correct |
6 ms |
1188 KB |
Output is correct |
30 |
Correct |
28 ms |
1216 KB |
Output is correct |
31 |
Correct |
26 ms |
1216 KB |
Output is correct |
32 |
Correct |
28 ms |
1244 KB |
Output is correct |
33 |
Correct |
62 ms |
7044 KB |
Output is correct |
34 |
Correct |
54 ms |
7116 KB |
Output is correct |
35 |
Correct |
77 ms |
7884 KB |
Output is correct |
36 |
Correct |
328 ms |
7664 KB |
Output is correct |
37 |
Correct |
343 ms |
7776 KB |
Output is correct |
38 |
Correct |
333 ms |
7796 KB |
Output is correct |
39 |
Correct |
473 ms |
6216 KB |
Output is correct |
40 |
Correct |
541 ms |
6244 KB |
Output is correct |
41 |
Correct |
498 ms |
6212 KB |
Output is correct |
42 |
Correct |
287 ms |
6748 KB |
Output is correct |
43 |
Correct |
334 ms |
7748 KB |
Output is correct |
44 |
Correct |
355 ms |
7756 KB |
Output is correct |
45 |
Correct |
335 ms |
7752 KB |
Output is correct |
46 |
Correct |
334 ms |
7748 KB |
Output is correct |
47 |
Correct |
338 ms |
7740 KB |
Output is correct |
48 |
Correct |
352 ms |
7752 KB |
Output is correct |
49 |
Correct |
338 ms |
7760 KB |
Output is correct |
50 |
Correct |
339 ms |
7740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
452 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
3 ms |
860 KB |
Output is correct |
20 |
Correct |
3 ms |
832 KB |
Output is correct |
21 |
Correct |
3 ms |
688 KB |
Output is correct |
22 |
Correct |
13 ms |
840 KB |
Output is correct |
23 |
Correct |
15 ms |
836 KB |
Output is correct |
24 |
Correct |
12 ms |
836 KB |
Output is correct |
25 |
Correct |
16 ms |
832 KB |
Output is correct |
26 |
Correct |
13 ms |
1092 KB |
Output is correct |
27 |
Correct |
195 ms |
22528 KB |
Output is correct |
28 |
Correct |
234 ms |
22684 KB |
Output is correct |
29 |
Correct |
221 ms |
22524 KB |
Output is correct |
30 |
Correct |
164 ms |
19140 KB |
Output is correct |
31 |
Correct |
1044 ms |
20776 KB |
Output is correct |
32 |
Correct |
1142 ms |
20932 KB |
Output is correct |
33 |
Correct |
1070 ms |
20960 KB |
Output is correct |
34 |
Correct |
1115 ms |
20808 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
292 ms |
7884 KB |
Output is correct |
37 |
Correct |
994 ms |
24128 KB |
Output is correct |
38 |
Correct |
1006 ms |
24268 KB |
Output is correct |
39 |
Correct |
924 ms |
23880 KB |
Output is correct |
40 |
Correct |
429 ms |
12728 KB |
Output is correct |
41 |
Correct |
215 ms |
7072 KB |
Output is correct |
42 |
Correct |
41 ms |
1836 KB |
Output is correct |
43 |
Correct |
1020 ms |
24272 KB |
Output is correct |
44 |
Correct |
832 ms |
24632 KB |
Output is correct |
45 |
Correct |
1049 ms |
23904 KB |
Output is correct |
46 |
Correct |
1419 ms |
23104 KB |
Output is correct |
47 |
Correct |
568 ms |
24428 KB |
Output is correct |
48 |
Correct |
1188 ms |
23404 KB |
Output is correct |
49 |
Correct |
1188 ms |
23804 KB |
Output is correct |
50 |
Correct |
503 ms |
24708 KB |
Output is correct |
51 |
Correct |
6 ms |
1188 KB |
Output is correct |
52 |
Correct |
7 ms |
1260 KB |
Output is correct |
53 |
Correct |
6 ms |
1188 KB |
Output is correct |
54 |
Correct |
28 ms |
1216 KB |
Output is correct |
55 |
Correct |
26 ms |
1216 KB |
Output is correct |
56 |
Correct |
28 ms |
1244 KB |
Output is correct |
57 |
Correct |
62 ms |
7044 KB |
Output is correct |
58 |
Correct |
54 ms |
7116 KB |
Output is correct |
59 |
Correct |
77 ms |
7884 KB |
Output is correct |
60 |
Correct |
328 ms |
7664 KB |
Output is correct |
61 |
Correct |
343 ms |
7776 KB |
Output is correct |
62 |
Correct |
333 ms |
7796 KB |
Output is correct |
63 |
Correct |
473 ms |
6216 KB |
Output is correct |
64 |
Correct |
541 ms |
6244 KB |
Output is correct |
65 |
Correct |
498 ms |
6212 KB |
Output is correct |
66 |
Correct |
287 ms |
6748 KB |
Output is correct |
67 |
Correct |
334 ms |
7748 KB |
Output is correct |
68 |
Correct |
355 ms |
7756 KB |
Output is correct |
69 |
Correct |
335 ms |
7752 KB |
Output is correct |
70 |
Correct |
334 ms |
7748 KB |
Output is correct |
71 |
Correct |
338 ms |
7740 KB |
Output is correct |
72 |
Correct |
352 ms |
7752 KB |
Output is correct |
73 |
Correct |
338 ms |
7760 KB |
Output is correct |
74 |
Correct |
339 ms |
7740 KB |
Output is correct |
75 |
Correct |
223 ms |
25240 KB |
Output is correct |
76 |
Correct |
279 ms |
24704 KB |
Output is correct |
77 |
Correct |
239 ms |
24920 KB |
Output is correct |
78 |
Correct |
158 ms |
21448 KB |
Output is correct |
79 |
Correct |
355 ms |
24668 KB |
Output is correct |
80 |
Correct |
164 ms |
21612 KB |
Output is correct |
81 |
Correct |
1136 ms |
24140 KB |
Output is correct |
82 |
Correct |
1049 ms |
24052 KB |
Output is correct |
83 |
Correct |
1055 ms |
23872 KB |
Output is correct |
84 |
Correct |
1140 ms |
24728 KB |
Output is correct |
85 |
Correct |
1098 ms |
23972 KB |
Output is correct |
86 |
Correct |
1071 ms |
24048 KB |
Output is correct |
87 |
Correct |
1082 ms |
24236 KB |
Output is correct |
88 |
Correct |
1747 ms |
19644 KB |
Output is correct |
89 |
Correct |
1616 ms |
19624 KB |
Output is correct |
90 |
Correct |
1554 ms |
19468 KB |
Output is correct |
91 |
Correct |
1601 ms |
19440 KB |
Output is correct |
92 |
Correct |
1650 ms |
19544 KB |
Output is correct |
93 |
Correct |
1369 ms |
23168 KB |
Output is correct |
94 |
Correct |
1430 ms |
23472 KB |
Output is correct |
95 |
Correct |
1325 ms |
23204 KB |
Output is correct |
96 |
Correct |
1356 ms |
23040 KB |
Output is correct |
97 |
Correct |
1547 ms |
22924 KB |
Output is correct |
98 |
Correct |
1203 ms |
23472 KB |
Output is correct |
99 |
Correct |
1339 ms |
23236 KB |
Output is correct |
100 |
Correct |
1387 ms |
23060 KB |
Output is correct |
101 |
Correct |
1183 ms |
23776 KB |
Output is correct |
102 |
Correct |
1359 ms |
23328 KB |
Output is correct |
103 |
Correct |
1429 ms |
23236 KB |
Output is correct |
104 |
Correct |
1345 ms |
23040 KB |
Output is correct |
105 |
Correct |
953 ms |
21264 KB |
Output is correct |
106 |
Correct |
1142 ms |
23984 KB |
Output is correct |
107 |
Correct |
1130 ms |
23968 KB |
Output is correct |
108 |
Correct |
1149 ms |
24080 KB |
Output is correct |
109 |
Correct |
1146 ms |
23928 KB |
Output is correct |
110 |
Correct |
1138 ms |
23988 KB |
Output is correct |
111 |
Correct |
1147 ms |
23904 KB |
Output is correct |
112 |
Correct |
1150 ms |
23872 KB |
Output is correct |
113 |
Correct |
1154 ms |
23792 KB |
Output is correct |
114 |
Correct |
1144 ms |
23968 KB |
Output is correct |
115 |
Correct |
1132 ms |
23996 KB |
Output is correct |
116 |
Correct |
1086 ms |
24056 KB |
Output is correct |