#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 3e5;
int n;
int gridSize;
vector<pair<int,pair<int,int>>> circles(MAX);
unordered_map<int,vector<int>> grid;
set<pair<int,int>> cur;
vector<int> elim(MAX,-1);
int dist(pair<int,int> p1, pair<int,int> p2) {return (p2.first-p1.first)*(p2.first-p1.first) + (p2.second-p1.second)*(p2.second-p1.second);}
bool intsct(pair<int,pair<int,int>> c1, pair<int,pair<int,int>> c2) {return dist(c1.second,c2.second) <= (c1.first+c2.first)*(c1.first+c2.first);}
int toInt(int xbin, int ybin) {return xbin + ybin * (int)(5e9);}
void makeGrid() {
grid.clear();
grid.reserve(count(elim.begin(),elim.end(),-1));
for (int i = 0; i < n; i++) {
if (elim[i] != -1) continue;
auto c = circles[i]; auto p = c.second;
int xbin = p.first/gridSize; int ybin = p.second/gridSize;
// cout << toInt(p) << "\n";
//assert (toInt(p) < numeric_limits<long long>::max());
if (grid.count(toInt(xbin,ybin)) == 0) grid[toInt(xbin,ybin)] = {i};
else grid[toInt(xbin,ybin)].push_back(i);
}
}
main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
int x,y,r; cin >> x >> y >> r;
circles[i] = make_pair(r,make_pair(x,y));
cur.insert(make_pair(-r,i));
}
gridSize = 1e18;
makeGrid();
while (cur.size() > 0) {
int i = cur.begin()->second;
auto top = circles[i]; auto p = top.second;
if (top.first < gridSize/2) {
gridSize = top.first;
makeGrid();
}
int xbinTop = p.first/gridSize; int ybinTop = p.second/gridSize;
for (int xbin = xbinTop-2; xbin <= xbinTop + 2; xbin++) {
for (int ybin = ybinTop-2; ybin <= ybinTop + 2; ybin++) {
for (int j: grid[toInt(xbin,ybin)]) {
if (elim[j] == -1 && intsct(top,circles[j])) {
// cout << i+1 << " " << j+1 << "\n";
elim[j] = i;
assert(cur.count(make_pair(-circles[j].first,j)) == 1);
cur.erase(make_pair(-circles[j].first,j));
}
}
}
}
/// break;
}
for (int i = 0; i < n; i++) {
cout << elim[i]+1 << " ";
}
cout << "\n";
return 0;
}
Compilation message
circle_selection.cpp:35:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12288 KB |
Output is correct |
2 |
Correct |
14 ms |
12288 KB |
Output is correct |
3 |
Correct |
12 ms |
12288 KB |
Output is correct |
4 |
Correct |
14 ms |
12288 KB |
Output is correct |
5 |
Correct |
12 ms |
12288 KB |
Output is correct |
6 |
Correct |
13 ms |
12288 KB |
Output is correct |
7 |
Correct |
14 ms |
12288 KB |
Output is correct |
8 |
Correct |
13 ms |
12224 KB |
Output is correct |
9 |
Correct |
15 ms |
14668 KB |
Output is correct |
10 |
Correct |
13 ms |
12288 KB |
Output is correct |
11 |
Correct |
16 ms |
14720 KB |
Output is correct |
12 |
Correct |
18 ms |
14720 KB |
Output is correct |
13 |
Correct |
16 ms |
14796 KB |
Output is correct |
14 |
Correct |
17 ms |
14720 KB |
Output is correct |
15 |
Correct |
15 ms |
14720 KB |
Output is correct |
16 |
Correct |
18 ms |
14720 KB |
Output is correct |
17 |
Correct |
16 ms |
12416 KB |
Output is correct |
18 |
Correct |
14 ms |
12416 KB |
Output is correct |
19 |
Correct |
25 ms |
12876 KB |
Output is correct |
20 |
Correct |
25 ms |
12800 KB |
Output is correct |
21 |
Correct |
36 ms |
15224 KB |
Output is correct |
22 |
Correct |
47 ms |
15736 KB |
Output is correct |
23 |
Correct |
50 ms |
15736 KB |
Output is correct |
24 |
Correct |
57 ms |
15928 KB |
Output is correct |
25 |
Correct |
46 ms |
15736 KB |
Output is correct |
26 |
Correct |
60 ms |
15864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1179 ms |
38228 KB |
Output is correct |
2 |
Correct |
1142 ms |
35924 KB |
Output is correct |
3 |
Correct |
1180 ms |
37668 KB |
Output is correct |
4 |
Correct |
1056 ms |
38344 KB |
Output is correct |
5 |
Correct |
1119 ms |
35908 KB |
Output is correct |
6 |
Correct |
2738 ms |
74644 KB |
Output is correct |
7 |
Correct |
1080 ms |
41504 KB |
Output is correct |
8 |
Correct |
1279 ms |
42796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12288 KB |
Output is correct |
2 |
Correct |
1805 ms |
87792 KB |
Output is correct |
3 |
Execution timed out |
3066 ms |
263924 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3064 ms |
263204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12288 KB |
Output is correct |
2 |
Correct |
14 ms |
12288 KB |
Output is correct |
3 |
Correct |
12 ms |
12288 KB |
Output is correct |
4 |
Correct |
14 ms |
12288 KB |
Output is correct |
5 |
Correct |
12 ms |
12288 KB |
Output is correct |
6 |
Correct |
13 ms |
12288 KB |
Output is correct |
7 |
Correct |
14 ms |
12288 KB |
Output is correct |
8 |
Correct |
13 ms |
12224 KB |
Output is correct |
9 |
Correct |
15 ms |
14668 KB |
Output is correct |
10 |
Correct |
13 ms |
12288 KB |
Output is correct |
11 |
Correct |
16 ms |
14720 KB |
Output is correct |
12 |
Correct |
18 ms |
14720 KB |
Output is correct |
13 |
Correct |
16 ms |
14796 KB |
Output is correct |
14 |
Correct |
17 ms |
14720 KB |
Output is correct |
15 |
Correct |
15 ms |
14720 KB |
Output is correct |
16 |
Correct |
18 ms |
14720 KB |
Output is correct |
17 |
Correct |
16 ms |
12416 KB |
Output is correct |
18 |
Correct |
14 ms |
12416 KB |
Output is correct |
19 |
Correct |
25 ms |
12876 KB |
Output is correct |
20 |
Correct |
25 ms |
12800 KB |
Output is correct |
21 |
Correct |
36 ms |
15224 KB |
Output is correct |
22 |
Correct |
47 ms |
15736 KB |
Output is correct |
23 |
Correct |
50 ms |
15736 KB |
Output is correct |
24 |
Correct |
57 ms |
15928 KB |
Output is correct |
25 |
Correct |
46 ms |
15736 KB |
Output is correct |
26 |
Correct |
60 ms |
15864 KB |
Output is correct |
27 |
Correct |
44 ms |
15628 KB |
Output is correct |
28 |
Correct |
37 ms |
13348 KB |
Output is correct |
29 |
Correct |
35 ms |
13348 KB |
Output is correct |
30 |
Correct |
91 ms |
19236 KB |
Output is correct |
31 |
Correct |
93 ms |
19236 KB |
Output is correct |
32 |
Correct |
108 ms |
19408 KB |
Output is correct |
33 |
Correct |
343 ms |
20736 KB |
Output is correct |
34 |
Correct |
349 ms |
21108 KB |
Output is correct |
35 |
Correct |
390 ms |
21572 KB |
Output is correct |
36 |
Correct |
1819 ms |
89032 KB |
Output is correct |
37 |
Correct |
1789 ms |
88652 KB |
Output is correct |
38 |
Correct |
1904 ms |
88544 KB |
Output is correct |
39 |
Correct |
715 ms |
36172 KB |
Output is correct |
40 |
Correct |
663 ms |
36196 KB |
Output is correct |
41 |
Correct |
671 ms |
35960 KB |
Output is correct |
42 |
Correct |
354 ms |
27352 KB |
Output is correct |
43 |
Correct |
1470 ms |
137416 KB |
Output is correct |
44 |
Correct |
1526 ms |
137596 KB |
Output is correct |
45 |
Correct |
1453 ms |
137520 KB |
Output is correct |
46 |
Correct |
1599 ms |
137588 KB |
Output is correct |
47 |
Correct |
1544 ms |
137672 KB |
Output is correct |
48 |
Correct |
1503 ms |
137692 KB |
Output is correct |
49 |
Correct |
1692 ms |
137740 KB |
Output is correct |
50 |
Correct |
1728 ms |
137524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12288 KB |
Output is correct |
2 |
Correct |
14 ms |
12288 KB |
Output is correct |
3 |
Correct |
12 ms |
12288 KB |
Output is correct |
4 |
Correct |
14 ms |
12288 KB |
Output is correct |
5 |
Correct |
12 ms |
12288 KB |
Output is correct |
6 |
Correct |
13 ms |
12288 KB |
Output is correct |
7 |
Correct |
14 ms |
12288 KB |
Output is correct |
8 |
Correct |
13 ms |
12224 KB |
Output is correct |
9 |
Correct |
15 ms |
14668 KB |
Output is correct |
10 |
Correct |
13 ms |
12288 KB |
Output is correct |
11 |
Correct |
16 ms |
14720 KB |
Output is correct |
12 |
Correct |
18 ms |
14720 KB |
Output is correct |
13 |
Correct |
16 ms |
14796 KB |
Output is correct |
14 |
Correct |
17 ms |
14720 KB |
Output is correct |
15 |
Correct |
15 ms |
14720 KB |
Output is correct |
16 |
Correct |
18 ms |
14720 KB |
Output is correct |
17 |
Correct |
16 ms |
12416 KB |
Output is correct |
18 |
Correct |
14 ms |
12416 KB |
Output is correct |
19 |
Correct |
25 ms |
12876 KB |
Output is correct |
20 |
Correct |
25 ms |
12800 KB |
Output is correct |
21 |
Correct |
36 ms |
15224 KB |
Output is correct |
22 |
Correct |
47 ms |
15736 KB |
Output is correct |
23 |
Correct |
50 ms |
15736 KB |
Output is correct |
24 |
Correct |
57 ms |
15928 KB |
Output is correct |
25 |
Correct |
46 ms |
15736 KB |
Output is correct |
26 |
Correct |
60 ms |
15864 KB |
Output is correct |
27 |
Correct |
1179 ms |
38228 KB |
Output is correct |
28 |
Correct |
1142 ms |
35924 KB |
Output is correct |
29 |
Correct |
1180 ms |
37668 KB |
Output is correct |
30 |
Correct |
1056 ms |
38344 KB |
Output is correct |
31 |
Correct |
1119 ms |
35908 KB |
Output is correct |
32 |
Correct |
2738 ms |
74644 KB |
Output is correct |
33 |
Correct |
1080 ms |
41504 KB |
Output is correct |
34 |
Correct |
1279 ms |
42796 KB |
Output is correct |
35 |
Correct |
13 ms |
12288 KB |
Output is correct |
36 |
Correct |
1805 ms |
87792 KB |
Output is correct |
37 |
Execution timed out |
3066 ms |
263924 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |