#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <time.h>
#pragma once
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
struct uint64_hash {
static inline uint64_t rotr(uint64_t x, unsigned k) {
return (x >> k) | (x << (8U * sizeof(uint64_t) - k));
}
static inline uint64_t hash_int(uint64_t x) noexcept {
auto h1 = x * (uint64_t)(0xA24BAED4963EE407);
auto h2 = rotr(x, 32U) * (uint64_t)(0x9FB21C651E98DF25);
auto h = rotr(h1 + h2, 32U);
return h;
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
return hash_int(x + FIXED_RANDOM);
}
};
template <typename K, typename V, typename Hash = uint64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
template <typename K, typename Hash = uint64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;
template <typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
using namespace std;
const int MAX_CERCLE = 4e5+42, INF = 1e9;
struct Cercle{
long long xCentre, yCentre, rayon, id;
bool operator<(Cercle autre) {
if(rayon == autre.rayon)
return id < autre.id;
return rayon > autre.rayon;
}
bool intersecte(Cercle autre) {
long long xDist = xCentre - autre.xCentre, yDist = yCentre - autre.yCentre;
long long rDist = rayon + autre.rayon;
return xDist * xDist + yDist * yDist <= rDist * rDist;
}
};
int nbCercle;
Cercle cercle[MAX_CERCLE];
void input() {
cin >> nbCercle;
for(int idCercle = 0; idCercle < nbCercle; idCercle++) {
cin >> cercle[idCercle].xCentre >> cercle[idCercle].yCentre >> cercle[idCercle].rayon;
cercle[idCercle].xCentre += INF;
cercle[idCercle].yCentre += INF;
cercle[idCercle].id = idCercle;
}
sort(cercle, cercle + nbCercle);
}
hash_map<long long, vector<int>> grille;
bool enleve[MAX_CERCLE] = {0};
void ajoutCercleGrille(int idCercle, long long taille) {
if(enleve[idCercle])
return;
long long xGrille = cercle[idCercle].xCentre / taille, yGrille = cercle[idCercle].yCentre / taille;
grille[(xGrille << 32) + yGrille].push_back(idCercle);
}
void calcGrille(long long taille) {
for(int cur = 0; cur < nbCercle; cur++) {
ajoutCercleGrille(cur, taille);
}
}
int quiEnleve[MAX_CERCLE];
long long tailleGrille = (1e12);
int main() {
clock_t t = clock();
ios::sync_with_stdio(false);
cin.tie(0);
input();
for(int grand = 0; grand < nbCercle; grand++) {
if(enleve[grand])
continue;
while(tailleGrille/2 > cercle[grand].rayon) {
tailleGrille /= 2;
calcGrille(tailleGrille);
}
long long xGrille = cercle[grand].xCentre / tailleGrille, yGrille = cercle[grand].yCentre / tailleGrille;
vector<int> quiReste;
for(int type = 0; type < 2; type++) {
for(int deltaX = -2; deltaX <= 2; deltaX++) {
for(int deltaY = -2; deltaY <= 2; deltaY++) {
long long nouvX = xGrille + deltaX, nouvY = yGrille + deltaY;
if(type == 1) {
grille[(nouvX << 32) + nouvY].clear();
continue;
}
for(auto autre : grille[(nouvX << 32) + nouvY]) {
if(cercle[grand].intersecte(cercle[autre]) && !enleve[autre]) {
enleve[autre] = 1;
quiEnleve[cercle[autre].id] = cercle[grand].id;
}
if(!cercle[grand].intersecte(cercle[autre])) {
quiReste.push_back(autre);
}
}
}
}
}
for(auto nouveau : quiReste) {
ajoutCercleGrille(nouveau, tailleGrille);
}
}
for(int cur = 0; cur < nbCercle; cur++) {
cout << quiEnleve[cur]+1 << " ";
}
}
Compilation message
circle_selection.cpp:6:9: warning: #pragma once in main file
6 | #pragma once
| ^~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:94:13: warning: unused variable 't' [-Wunused-variable]
94 | clock_t t = clock();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
984 KB |
Output is correct |
20 |
Correct |
4 ms |
880 KB |
Output is correct |
21 |
Correct |
4 ms |
1016 KB |
Output is correct |
22 |
Correct |
80 ms |
34476 KB |
Output is correct |
23 |
Correct |
68 ms |
34492 KB |
Output is correct |
24 |
Correct |
69 ms |
34524 KB |
Output is correct |
25 |
Correct |
76 ms |
35500 KB |
Output is correct |
26 |
Correct |
66 ms |
34816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
39636 KB |
Output is correct |
2 |
Correct |
289 ms |
56488 KB |
Output is correct |
3 |
Correct |
220 ms |
42556 KB |
Output is correct |
4 |
Correct |
218 ms |
37244 KB |
Output is correct |
5 |
Correct |
536 ms |
117056 KB |
Output is correct |
6 |
Correct |
1297 ms |
349168 KB |
Output is correct |
7 |
Correct |
580 ms |
131008 KB |
Output is correct |
8 |
Correct |
735 ms |
168008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1303 ms |
537532 KB |
Output is correct |
3 |
Runtime error |
2335 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2399 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
984 KB |
Output is correct |
20 |
Correct |
4 ms |
880 KB |
Output is correct |
21 |
Correct |
4 ms |
1016 KB |
Output is correct |
22 |
Correct |
80 ms |
34476 KB |
Output is correct |
23 |
Correct |
68 ms |
34492 KB |
Output is correct |
24 |
Correct |
69 ms |
34524 KB |
Output is correct |
25 |
Correct |
76 ms |
35500 KB |
Output is correct |
26 |
Correct |
66 ms |
34816 KB |
Output is correct |
27 |
Correct |
10 ms |
1728 KB |
Output is correct |
28 |
Correct |
8 ms |
1684 KB |
Output is correct |
29 |
Correct |
7 ms |
1556 KB |
Output is correct |
30 |
Correct |
140 ms |
68256 KB |
Output is correct |
31 |
Correct |
158 ms |
68080 KB |
Output is correct |
32 |
Correct |
154 ms |
69096 KB |
Output is correct |
33 |
Correct |
81 ms |
12736 KB |
Output is correct |
34 |
Correct |
72 ms |
12784 KB |
Output is correct |
35 |
Correct |
82 ms |
14264 KB |
Output is correct |
36 |
Correct |
1489 ms |
556152 KB |
Output is correct |
37 |
Correct |
1453 ms |
563476 KB |
Output is correct |
38 |
Correct |
1484 ms |
554576 KB |
Output is correct |
39 |
Correct |
714 ms |
45892 KB |
Output is correct |
40 |
Correct |
728 ms |
45560 KB |
Output is correct |
41 |
Correct |
651 ms |
45852 KB |
Output is correct |
42 |
Correct |
265 ms |
49864 KB |
Output is correct |
43 |
Correct |
1286 ms |
546324 KB |
Output is correct |
44 |
Correct |
1268 ms |
546492 KB |
Output is correct |
45 |
Correct |
1244 ms |
546500 KB |
Output is correct |
46 |
Correct |
1283 ms |
546508 KB |
Output is correct |
47 |
Correct |
1239 ms |
546556 KB |
Output is correct |
48 |
Correct |
1217 ms |
546404 KB |
Output is correct |
49 |
Correct |
1241 ms |
546544 KB |
Output is correct |
50 |
Correct |
1268 ms |
546448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
984 KB |
Output is correct |
20 |
Correct |
4 ms |
880 KB |
Output is correct |
21 |
Correct |
4 ms |
1016 KB |
Output is correct |
22 |
Correct |
80 ms |
34476 KB |
Output is correct |
23 |
Correct |
68 ms |
34492 KB |
Output is correct |
24 |
Correct |
69 ms |
34524 KB |
Output is correct |
25 |
Correct |
76 ms |
35500 KB |
Output is correct |
26 |
Correct |
66 ms |
34816 KB |
Output is correct |
27 |
Correct |
226 ms |
39636 KB |
Output is correct |
28 |
Correct |
289 ms |
56488 KB |
Output is correct |
29 |
Correct |
220 ms |
42556 KB |
Output is correct |
30 |
Correct |
218 ms |
37244 KB |
Output is correct |
31 |
Correct |
536 ms |
117056 KB |
Output is correct |
32 |
Correct |
1297 ms |
349168 KB |
Output is correct |
33 |
Correct |
580 ms |
131008 KB |
Output is correct |
34 |
Correct |
735 ms |
168008 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
1303 ms |
537532 KB |
Output is correct |
37 |
Runtime error |
2335 ms |
1048576 KB |
Execution killed with signal 9 |
38 |
Halted |
0 ms |
0 KB |
- |