답안 #658186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658186 2022-11-12T10:58:10 Z Richem 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 895460 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 > 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 = -5; deltaX <= 5; deltaX++) {
                for(int deltaY = -5; deltaY <= 5; 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 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 372 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 2 ms 1088 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 2 ms 576 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 552 KB Output is correct
19 Correct 5 ms 1112 KB Output is correct
20 Correct 4 ms 1112 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 174 ms 39148 KB Output is correct
23 Correct 184 ms 39104 KB Output is correct
24 Correct 206 ms 38964 KB Output is correct
25 Correct 163 ms 40240 KB Output is correct
26 Correct 182 ms 39336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 244 ms 45208 KB Output is correct
2 Correct 365 ms 82600 KB Output is correct
3 Correct 244 ms 47936 KB Output is correct
4 Correct 227 ms 42800 KB Output is correct
5 Correct 695 ms 130148 KB Output is correct
6 Execution timed out 3037 ms 567400 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 3103 ms 895460 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3100 ms 566256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 372 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 2 ms 1088 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 2 ms 576 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 552 KB Output is correct
19 Correct 5 ms 1112 KB Output is correct
20 Correct 4 ms 1112 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 174 ms 39148 KB Output is correct
23 Correct 184 ms 39104 KB Output is correct
24 Correct 206 ms 38964 KB Output is correct
25 Correct 163 ms 40240 KB Output is correct
26 Correct 182 ms 39336 KB Output is correct
27 Correct 9 ms 2104 KB Output is correct
28 Correct 11 ms 2152 KB Output is correct
29 Correct 11 ms 2084 KB Output is correct
30 Correct 409 ms 77672 KB Output is correct
31 Correct 405 ms 77404 KB Output is correct
32 Correct 416 ms 78556 KB Output is correct
33 Correct 80 ms 15192 KB Output is correct
34 Correct 78 ms 14504 KB Output is correct
35 Correct 91 ms 16860 KB Output is correct
36 Execution timed out 3077 ms 711656 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 372 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 2 ms 1108 KB Output is correct
12 Correct 2 ms 1108 KB Output is correct
13 Correct 2 ms 1088 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 2 ms 576 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 552 KB Output is correct
19 Correct 5 ms 1112 KB Output is correct
20 Correct 4 ms 1112 KB Output is correct
21 Correct 5 ms 1364 KB Output is correct
22 Correct 174 ms 39148 KB Output is correct
23 Correct 184 ms 39104 KB Output is correct
24 Correct 206 ms 38964 KB Output is correct
25 Correct 163 ms 40240 KB Output is correct
26 Correct 182 ms 39336 KB Output is correct
27 Correct 244 ms 45208 KB Output is correct
28 Correct 365 ms 82600 KB Output is correct
29 Correct 244 ms 47936 KB Output is correct
30 Correct 227 ms 42800 KB Output is correct
31 Correct 695 ms 130148 KB Output is correct
32 Execution timed out 3037 ms 567400 KB Time limit exceeded
33 Halted 0 ms 0 KB -