Submission #658195

# Submission time Handle Problem Language Result Execution time Memory
658195 2022-11-12T11:14:39 Z Richem Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 530472 KB
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_CERCLE = 3e5+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);
}

unordered_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() {
    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 = -3; deltaX <= 3; deltaX++) {
                for(int deltaY = -3; deltaY <= 3; 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 << " ";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 4 ms 804 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 89 ms 18612 KB Output is correct
23 Correct 75 ms 18388 KB Output is correct
24 Correct 72 ms 18556 KB Output is correct
25 Correct 79 ms 19696 KB Output is correct
26 Correct 82 ms 18832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 28056 KB Output is correct
2 Correct 317 ms 47760 KB Output is correct
3 Correct 220 ms 29268 KB Output is correct
4 Correct 204 ms 26336 KB Output is correct
5 Correct 571 ms 65276 KB Output is correct
6 Correct 2374 ms 275692 KB Output is correct
7 Correct 653 ms 73440 KB Output is correct
8 Correct 942 ms 112772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2283 ms 318908 KB Output is correct
3 Execution timed out 3104 ms 506968 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3085 ms 530472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 4 ms 804 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 89 ms 18612 KB Output is correct
23 Correct 75 ms 18388 KB Output is correct
24 Correct 72 ms 18556 KB Output is correct
25 Correct 79 ms 19696 KB Output is correct
26 Correct 82 ms 18832 KB Output is correct
27 Correct 8 ms 1240 KB Output is correct
28 Correct 8 ms 1240 KB Output is correct
29 Correct 7 ms 1320 KB Output is correct
30 Correct 197 ms 36300 KB Output is correct
31 Correct 197 ms 36016 KB Output is correct
32 Correct 240 ms 37072 KB Output is correct
33 Correct 73 ms 8996 KB Output is correct
34 Correct 71 ms 8964 KB Output is correct
35 Correct 79 ms 10340 KB Output is correct
36 Correct 2665 ms 350508 KB Output is correct
37 Correct 2774 ms 355936 KB Output is correct
38 Correct 2612 ms 345008 KB Output is correct
39 Correct 1370 ms 39944 KB Output is correct
40 Correct 1275 ms 39916 KB Output is correct
41 Correct 1104 ms 39840 KB Output is correct
42 Correct 338 ms 26932 KB Output is correct
43 Correct 2454 ms 265792 KB Output is correct
44 Correct 2047 ms 266308 KB Output is correct
45 Correct 2107 ms 265924 KB Output is correct
46 Correct 2128 ms 266188 KB Output is correct
47 Correct 1943 ms 266264 KB Output is correct
48 Correct 1972 ms 266480 KB Output is correct
49 Correct 2041 ms 266476 KB Output is correct
50 Correct 2354 ms 266048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 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 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 4 ms 856 KB Output is correct
20 Correct 4 ms 804 KB Output is correct
21 Correct 5 ms 856 KB Output is correct
22 Correct 89 ms 18612 KB Output is correct
23 Correct 75 ms 18388 KB Output is correct
24 Correct 72 ms 18556 KB Output is correct
25 Correct 79 ms 19696 KB Output is correct
26 Correct 82 ms 18832 KB Output is correct
27 Correct 219 ms 28056 KB Output is correct
28 Correct 317 ms 47760 KB Output is correct
29 Correct 220 ms 29268 KB Output is correct
30 Correct 204 ms 26336 KB Output is correct
31 Correct 571 ms 65276 KB Output is correct
32 Correct 2374 ms 275692 KB Output is correct
33 Correct 653 ms 73440 KB Output is correct
34 Correct 942 ms 112772 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2283 ms 318908 KB Output is correct
37 Execution timed out 3104 ms 506968 KB Time limit exceeded
38 Halted 0 ms 0 KB -