Submission #658340

# Submission time Handle Problem Language Result Execution time Memory
658340 2022-11-12T20:32:31 Z hugo_pm Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 64892 KB
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <time.h>
#include <chrono>
#include <forward_list>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
    
struct uint64_hash {
    static inline uint64_t rotr(uint64_t x, unsigned k) {
    return (x >> k) | (x << (8U * sizeof(uint64_t) - k));
    }
    
    static inline uint64_t hash_int(uint64_t x) noexcept {
    auto h1 = x * (uint64_t)(0xA24BAED4963EE407);
    auto h2 = rotr(x, 32U) * (uint64_t)(0x9FB21C651E98DF25);
    auto h = rotr(h1 + h2, 32U);
    return h;
    }
    
    size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    return hash_int(x + FIXED_RANDOM);
    }
};
    
template <typename K, typename V, typename Hash = uint64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
template <typename K, typename Hash = uint64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;
template <typename T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
    
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;
    }
};
    
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);
}
    
hash_map<long long, forward_list<int>> grille;
bool enleve[MAX_CERCLE] = {0};
    
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;
    
        bool change = 0;
        while(tailleGrille/2 > cercle[grand].rayon) {
            tailleGrille /= 2;
            change = 1;
        }
    
        if(change) {
            grille.clear();
            for(int cur = 0; cur < nbCercle; cur++) {
                if(enleve[cur])
                    continue;
                long long xGrille = cercle[cur].xCentre / tailleGrille, yGrille = cercle[cur].yCentre / tailleGrille;
                
                grille[(xGrille << 32) + yGrille].push_front(cur);
            }
        }
    
        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.erase((nouvX << 32) + nouvY);
                        continue;
                    }
    
                    for(auto autre : grille[(nouvX << 32) + nouvY]) {
                        long long xDist = cercle[grand].xCentre - cercle[autre].xCentre, yDist = cercle[grand].yCentre - cercle[autre].yCentre;
                        long long rDist = cercle[grand].rayon + cercle[autre].rayon;
    
                        if(xDist * xDist + yDist * yDist <= rDist * rDist && !enleve[autre]) {
                            enleve[autre] = 1;
                            quiEnleve[cercle[autre].id] = cercle[grand].id;
                        }
                        if(xDist * xDist + yDist * yDist > rDist * rDist) {
                            quiReste.push_back(autre);
                        }
                    }
                }
            }
        }
    
        for(auto nouveau : quiReste) {
            if(enleve[nouveau])
                continue;
            long long xGrille = cercle[nouveau].xCentre / tailleGrille, yGrille = cercle[nouveau].yCentre / tailleGrille;
            
            grille[(xGrille << 32) + yGrille].push_front(nouveau);
        }
    }
    
    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 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 0 ms 340 KB Output is correct
8 Correct 0 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 4 ms 852 KB Output is correct
22 Correct 19 ms 1296 KB Output is correct
23 Correct 14 ms 1296 KB Output is correct
24 Correct 25 ms 1296 KB Output is correct
25 Correct 21 ms 1296 KB Output is correct
26 Correct 57 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 32056 KB Output is correct
2 Correct 210 ms 32048 KB Output is correct
3 Correct 186 ms 31872 KB Output is correct
4 Correct 178 ms 32072 KB Output is correct
5 Correct 245 ms 22600 KB Output is correct
6 Correct 1456 ms 26612 KB Output is correct
7 Correct 2608 ms 22480 KB Output is correct
8 Correct 354 ms 25204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 362 ms 17192 KB Output is correct
3 Correct 1593 ms 64480 KB Output is correct
4 Correct 1622 ms 63048 KB Output is correct
5 Correct 1167 ms 41068 KB Output is correct
6 Correct 532 ms 21120 KB Output is correct
7 Correct 224 ms 10456 KB Output is correct
8 Correct 40 ms 2532 KB Output is correct
9 Correct 1331 ms 64892 KB Output is correct
10 Correct 826 ms 41892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 64072 KB Output is correct
2 Correct 1380 ms 63804 KB Output is correct
3 Correct 334 ms 30060 KB Output is correct
4 Correct 1466 ms 63880 KB Output is correct
5 Correct 1368 ms 63900 KB Output is correct
6 Correct 276 ms 22484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 4 ms 852 KB Output is correct
22 Correct 19 ms 1296 KB Output is correct
23 Correct 14 ms 1296 KB Output is correct
24 Correct 25 ms 1296 KB Output is correct
25 Correct 21 ms 1296 KB Output is correct
26 Correct 57 ms 1296 KB Output is correct
27 Correct 7 ms 1364 KB Output is correct
28 Correct 6 ms 1364 KB Output is correct
29 Correct 6 ms 1364 KB Output is correct
30 Correct 34 ms 2332 KB Output is correct
31 Correct 30 ms 2364 KB Output is correct
32 Correct 48 ms 2320 KB Output is correct
33 Correct 59 ms 10700 KB Output is correct
34 Correct 60 ms 10700 KB Output is correct
35 Correct 64 ms 10196 KB Output is correct
36 Correct 384 ms 17196 KB Output is correct
37 Correct 366 ms 17260 KB Output is correct
38 Correct 395 ms 17268 KB Output is correct
39 Correct 1274 ms 14684 KB Output is correct
40 Correct 1331 ms 16004 KB Output is correct
41 Correct 1331 ms 15188 KB Output is correct
42 Correct 138 ms 18412 KB Output is correct
43 Correct 646 ms 17412 KB Output is correct
44 Correct 700 ms 17412 KB Output is correct
45 Correct 670 ms 17412 KB Output is correct
46 Correct 617 ms 17324 KB Output is correct
47 Correct 638 ms 17392 KB Output is correct
48 Correct 704 ms 17392 KB Output is correct
49 Correct 680 ms 17412 KB Output is correct
50 Correct 723 ms 17516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 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 0 ms 340 KB Output is correct
8 Correct 0 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 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 4 ms 852 KB Output is correct
22 Correct 19 ms 1296 KB Output is correct
23 Correct 14 ms 1296 KB Output is correct
24 Correct 25 ms 1296 KB Output is correct
25 Correct 21 ms 1296 KB Output is correct
26 Correct 57 ms 1296 KB Output is correct
27 Correct 182 ms 32056 KB Output is correct
28 Correct 210 ms 32048 KB Output is correct
29 Correct 186 ms 31872 KB Output is correct
30 Correct 178 ms 32072 KB Output is correct
31 Correct 245 ms 22600 KB Output is correct
32 Correct 1456 ms 26612 KB Output is correct
33 Correct 2608 ms 22480 KB Output is correct
34 Correct 354 ms 25204 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 362 ms 17192 KB Output is correct
37 Correct 1593 ms 64480 KB Output is correct
38 Correct 1622 ms 63048 KB Output is correct
39 Correct 1167 ms 41068 KB Output is correct
40 Correct 532 ms 21120 KB Output is correct
41 Correct 224 ms 10456 KB Output is correct
42 Correct 40 ms 2532 KB Output is correct
43 Correct 1331 ms 64892 KB Output is correct
44 Correct 826 ms 41892 KB Output is correct
45 Correct 1416 ms 64072 KB Output is correct
46 Correct 1380 ms 63804 KB Output is correct
47 Correct 334 ms 30060 KB Output is correct
48 Correct 1466 ms 63880 KB Output is correct
49 Correct 1368 ms 63900 KB Output is correct
50 Correct 276 ms 22484 KB Output is correct
51 Correct 7 ms 1364 KB Output is correct
52 Correct 6 ms 1364 KB Output is correct
53 Correct 6 ms 1364 KB Output is correct
54 Correct 34 ms 2332 KB Output is correct
55 Correct 30 ms 2364 KB Output is correct
56 Correct 48 ms 2320 KB Output is correct
57 Correct 59 ms 10700 KB Output is correct
58 Correct 60 ms 10700 KB Output is correct
59 Correct 64 ms 10196 KB Output is correct
60 Correct 384 ms 17196 KB Output is correct
61 Correct 366 ms 17260 KB Output is correct
62 Correct 395 ms 17268 KB Output is correct
63 Correct 1274 ms 14684 KB Output is correct
64 Correct 1331 ms 16004 KB Output is correct
65 Correct 1331 ms 15188 KB Output is correct
66 Correct 138 ms 18412 KB Output is correct
67 Correct 646 ms 17412 KB Output is correct
68 Correct 700 ms 17412 KB Output is correct
69 Correct 670 ms 17412 KB Output is correct
70 Correct 617 ms 17324 KB Output is correct
71 Correct 638 ms 17392 KB Output is correct
72 Correct 704 ms 17392 KB Output is correct
73 Correct 680 ms 17412 KB Output is correct
74 Correct 723 ms 17516 KB Output is correct
75 Correct 201 ms 31808 KB Output is correct
76 Correct 213 ms 30300 KB Output is correct
77 Correct 183 ms 32076 KB Output is correct
78 Correct 174 ms 31692 KB Output is correct
79 Correct 431 ms 30952 KB Output is correct
80 Correct 172 ms 31668 KB Output is correct
81 Execution timed out 3084 ms 64356 KB Time limit exceeded
82 Halted 0 ms 0 KB -