Submission #658196

# Submission time Handle Problem Language Result Execution time Memory
658196 2022-11-12T11:16:22 Z Richem Circle selection (APIO18_circle_selection) C++14
49 / 100
3000 ms 530936 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 = -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 << " ";
    }
}

# 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 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 0 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 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 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 856 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
21 Correct 4 ms 856 KB Output is correct
22 Correct 44 ms 11536 KB Output is correct
23 Correct 38 ms 11460 KB Output is correct
24 Correct 39 ms 11376 KB Output is correct
25 Correct 56 ms 14920 KB Output is correct
26 Correct 41 ms 11820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 28104 KB Output is correct
2 Correct 290 ms 47788 KB Output is correct
3 Correct 220 ms 28984 KB Output is correct
4 Correct 202 ms 26236 KB Output is correct
5 Correct 519 ms 61968 KB Output is correct
6 Correct 1799 ms 182648 KB Output is correct
7 Correct 571 ms 66880 KB Output is correct
8 Correct 756 ms 90520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1579 ms 187288 KB Output is correct
3 Execution timed out 3119 ms 509672 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3116 ms 530936 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 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 0 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 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 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 856 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
21 Correct 4 ms 856 KB Output is correct
22 Correct 44 ms 11536 KB Output is correct
23 Correct 38 ms 11460 KB Output is correct
24 Correct 39 ms 11376 KB Output is correct
25 Correct 56 ms 14920 KB Output is correct
26 Correct 41 ms 11820 KB Output is correct
27 Correct 7 ms 1240 KB Output is correct
28 Correct 7 ms 1240 KB Output is correct
29 Correct 7 ms 1240 KB Output is correct
30 Correct 110 ms 22220 KB Output is correct
31 Correct 121 ms 21972 KB Output is correct
32 Correct 131 ms 23064 KB Output is correct
33 Correct 70 ms 8912 KB Output is correct
34 Correct 69 ms 8976 KB Output is correct
35 Correct 82 ms 10040 KB Output is correct
36 Correct 2029 ms 245612 KB Output is correct
37 Correct 2078 ms 247536 KB Output is correct
38 Correct 1977 ms 243940 KB Output is correct
39 Correct 817 ms 35216 KB Output is correct
40 Correct 806 ms 35256 KB Output is correct
41 Correct 773 ms 35292 KB Output is correct
42 Correct 261 ms 26860 KB Output is correct
43 Correct 1456 ms 164692 KB Output is correct
44 Correct 1339 ms 165056 KB Output is correct
45 Correct 1500 ms 164848 KB Output is correct
46 Correct 1396 ms 164976 KB Output is correct
47 Correct 1322 ms 165088 KB Output is correct
48 Correct 1327 ms 165024 KB Output is correct
49 Correct 1396 ms 165120 KB Output is correct
50 Correct 1744 ms 164880 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 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 0 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 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 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 856 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
21 Correct 4 ms 856 KB Output is correct
22 Correct 44 ms 11536 KB Output is correct
23 Correct 38 ms 11460 KB Output is correct
24 Correct 39 ms 11376 KB Output is correct
25 Correct 56 ms 14920 KB Output is correct
26 Correct 41 ms 11820 KB Output is correct
27 Correct 216 ms 28104 KB Output is correct
28 Correct 290 ms 47788 KB Output is correct
29 Correct 220 ms 28984 KB Output is correct
30 Correct 202 ms 26236 KB Output is correct
31 Correct 519 ms 61968 KB Output is correct
32 Correct 1799 ms 182648 KB Output is correct
33 Correct 571 ms 66880 KB Output is correct
34 Correct 756 ms 90520 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1579 ms 187288 KB Output is correct
37 Execution timed out 3119 ms 509672 KB Time limit exceeded
38 Halted 0 ms 0 KB -