#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
const int MAX_ALED = 3e5+42;
struct Aled{
int xCentre, yCentre, rayon, id;
bool ragequit = false;
bool intersecte(Aled autre) {
int x = xCentre - autre.xCentre, y = yCentre - autre.yCentre;
return (x*x+y*y) <= (rayon + autre.rayon) * (rayon + autre.rayon);
}
bool operator<(Aled autre) {
if(rayon == autre.rayon)
return id < autre.id;
return rayon > autre.rayon;
}
};
struct Position{
long long int x,y;
unsigned long long int getId() {
return (x << 32) + y;
}
};
int nbAled;
Aled aled[MAX_ALED];
Aled triRayon[MAX_ALED];
void input() {
cin >> nbAled;
for(int iAled = 0; iAled < nbAled; iAled++) {
cin >> aled[iAled].xCentre >> aled[iAled].yCentre >> aled[iAled].rayon;
aled[iAled].xCentre += 1e9;
aled[iAled].yCentre += 1e9;
aled[iAled].id = iAled;
}
sort(aled, aled + nbAled);
}
unordered_map<long long int, vector<int>> enfer;
Position quelCase[MAX_ALED];
void calcGrille(int taille) {
enfer.clear();
for(int cur = 0; cur < nbAled; cur++) {
int xCase = aled[cur].xCentre / taille, yCase = aled[cur].yCentre / taille;
Position caseCur = {xCase, yCase};
enfer[caseCur.getId()].push_back(cur);
quelCase[cur] = {xCase, yCase};
}
}
bool retire[MAX_ALED] = {0};
int rep[MAX_ALED];
int tailleGrille;
int main() {
input();
tailleGrille = (1 << 30);
for(int curCercle = 0; curCercle < nbAled; curCercle++) {
if(retire[curCercle])
continue;
while(aled[curCercle].rayon < tailleGrille/2) {
tailleGrille /= 2;
calcGrille(tailleGrille);
}
for(int deltaX = -3; deltaX <= 3; deltaX++) {
for(int deltaY = -3; deltaY <= 3; deltaY++) {
int xCaseNouv = quelCase[curCercle].x + deltaX, yCaseNouv = quelCase[curCercle].y + deltaY;
Position caseNouv = {xCaseNouv, yCaseNouv};
if(xCaseNouv < 0 || yCaseNouv < 0)
continue;
for(auto autreCercle : enfer[caseNouv.getId()]) {
if(!retire[autreCercle] && aled[curCercle].intersecte(aled[autreCercle])) {
retire[autreCercle] = 1;
rep[aled[autreCercle].id] = aled[curCercle].id+1;
}
}
}
}
}
for(int curCercle = 0; curCercle < nbAled; curCercle++) {
cout << rep[curCercle] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
357 ms |
22860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3103 ms |
448796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
5 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |