Submission #658189

# Submission time Handle Problem Language Result Execution time Memory
658189 2022-11-12T11:04:47 Z Richem Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 557448 KB
#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 = (1e12);

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 << " ";
    }
}
# Verdict Execution time Memory 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 1 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 1 ms 540 KB Output is correct
19 Correct 4 ms 1112 KB Output is correct
20 Correct 4 ms 1136 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 80 ms 18972 KB Output is correct
23 Correct 84 ms 18984 KB Output is correct
24 Correct 89 ms 18856 KB Output is correct
25 Correct 93 ms 20116 KB Output is correct
26 Correct 86 ms 19332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 45160 KB Output is correct
2 Correct 325 ms 83308 KB Output is correct
3 Correct 233 ms 46196 KB Output is correct
4 Correct 227 ms 42768 KB Output is correct
5 Correct 601 ms 109564 KB Output is correct
6 Correct 2435 ms 322860 KB Output is correct
7 Correct 704 ms 114908 KB Output is correct
8 Correct 1052 ms 160284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2360 ms 326688 KB Output is correct
3 Execution timed out 3033 ms 529340 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3079 ms 557448 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 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 1 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 1 ms 540 KB Output is correct
19 Correct 4 ms 1112 KB Output is correct
20 Correct 4 ms 1136 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 80 ms 18972 KB Output is correct
23 Correct 84 ms 18984 KB Output is correct
24 Correct 89 ms 18856 KB Output is correct
25 Correct 93 ms 20116 KB Output is correct
26 Correct 86 ms 19332 KB Output is correct
27 Correct 9 ms 1748 KB Output is correct
28 Correct 8 ms 1872 KB Output is correct
29 Correct 9 ms 1748 KB Output is correct
30 Correct 213 ms 37192 KB Output is correct
31 Correct 191 ms 36920 KB Output is correct
32 Correct 240 ms 37884 KB Output is correct
33 Correct 77 ms 13696 KB Output is correct
34 Correct 75 ms 13796 KB Output is correct
35 Correct 85 ms 16428 KB Output is correct
36 Correct 2791 ms 359460 KB Output is correct
37 Correct 2759 ms 367296 KB Output is correct
38 Correct 2623 ms 356576 KB Output is correct
39 Correct 1376 ms 72940 KB Output is correct
40 Correct 1347 ms 72844 KB Output is correct
41 Correct 1093 ms 72960 KB Output is correct
42 Correct 311 ms 42220 KB Output is correct
43 Correct 2447 ms 279852 KB Output is correct
44 Correct 2004 ms 280420 KB Output is correct
45 Correct 2171 ms 280000 KB Output is correct
46 Correct 2152 ms 280224 KB Output is correct
47 Correct 1994 ms 280456 KB Output is correct
48 Correct 2067 ms 280500 KB Output is correct
49 Correct 2135 ms 280580 KB Output is correct
50 Correct 2447 ms 280124 KB Output is correct
# Verdict Execution time Memory 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 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 2 ms 724 KB Output is correct
14 Correct 2 ms 724 KB Output is correct
15 Correct 1 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 1 ms 540 KB Output is correct
19 Correct 4 ms 1112 KB Output is correct
20 Correct 4 ms 1136 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 80 ms 18972 KB Output is correct
23 Correct 84 ms 18984 KB Output is correct
24 Correct 89 ms 18856 KB Output is correct
25 Correct 93 ms 20116 KB Output is correct
26 Correct 86 ms 19332 KB Output is correct
27 Correct 225 ms 45160 KB Output is correct
28 Correct 325 ms 83308 KB Output is correct
29 Correct 233 ms 46196 KB Output is correct
30 Correct 227 ms 42768 KB Output is correct
31 Correct 601 ms 109564 KB Output is correct
32 Correct 2435 ms 322860 KB Output is correct
33 Correct 704 ms 114908 KB Output is correct
34 Correct 1052 ms 160284 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2360 ms 326688 KB Output is correct
37 Execution timed out 3033 ms 529340 KB Time limit exceeded
38 Halted 0 ms 0 KB -