#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
const int MAX_CERCLE = 3e5+42, INF = 1e9;
struct Cercle{
int xCentre, yCentre, rayon, id;
bool operator<(Cercle autre) {
if(rayon == autre.rayon)
return id < autre.id;
return rayon > autre.rayon;
}
bool intersecte(Cercle autre) {
int xDist = xCentre - autre.xCentre, yDist = yCentre - autre.yCentre;
int 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);
}
unordered_map<int, vector<int>> grille;
bool enleve[MAX_CERCLE] = {0};
void ajoutCercleGrille(int idCercle, int taille) {
if(enleve[idCercle])
return;
int xGrille = cercle[idCercle].xCentre / taille, yGrille = cercle[idCercle].yCentre / taille;
grille[(xGrille << 32) + yGrille].push_back(idCercle);
}
void calcGrille(int taille) {
for(int cur = 0; cur < nbCercle; cur++) {
ajoutCercleGrille(cur, taille);
}
}
int quiEnleve[MAX_CERCLE];
int tailleGrille = (1 << 30);
signed main() {
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);
}
int xGrille = cercle[grand].xCentre / tailleGrille, yGrille = cercle[grand].yCentre / tailleGrille;
vector<int> quiReste;
for(int type = 0; type < 2; type++) {
for(int deltaX = -3; deltaX <= 3; deltaX++) {
for(int deltaY = -3; deltaY <= 3; deltaY++) {
int 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 << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
17788 KB |
Output is correct |
2 |
Correct |
180 ms |
24048 KB |
Output is correct |
3 |
Correct |
175 ms |
21464 KB |
Output is correct |
4 |
Incorrect |
316 ms |
16952 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2379 ms |
319844 KB |
Output is correct |
3 |
Execution timed out |
3062 ms |
510856 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3104 ms |
531820 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |