Submission #658352

# Submission time Handle Problem Language Result Execution time Memory
658352 2022-11-12T21:21:16 Z hugo_pm Circle selection (APIO18_circle_selection) C++17
100 / 100
1674 ms 609972 KB
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <time.h>
#include <chrono>
#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);
}

// simulate hash_map<K, stack<V>>
template<typename K, typename V>
struct map2d {
    hash_map<K, int> to_last;
    vector<V> content;
    vector<int> prev;
    map2d() { clear(); }

    void push(K key, V value) {
        int location = content.size();
        content.push_back(value);
        prev.push_back(to_last[key]);
        to_last[key] = location;
    }
    
    bool pop(K key, V& popped) {
        int location = to_last[key];
        if (!location) return false;
        popped = content[location];
        to_last[key] = prev[location];
        return true;
    }

    bool empty(K key) {
        return to_last[key] == 0;
    }
    void erase(K key) {
        to_last[key] = 0;
    }
    void clear() {
        to_last.clear();
        content.resize(1);
        prev.resize(1);
    }
};
map2d<long long, 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.push((xGrille << 32) + yGrille, 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;
                    }

                    int autre;
                    while (grille.pop((nouvX << 32) + nouvY, autre)) {
                        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.push((xGrille << 32) + yGrille, nouveau);
        }
    }
    
    for(int cur = 0; cur < nbCercle; cur++) {
        cout << quiEnleve[cur]+1 << " ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 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 2 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 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 3 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 15 ms 5232 KB Output is correct
23 Correct 17 ms 6052 KB Output is correct
24 Correct 16 ms 5204 KB Output is correct
25 Correct 16 ms 5232 KB Output is correct
26 Correct 15 ms 5984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 15844 KB Output is correct
2 Correct 142 ms 17480 KB Output is correct
3 Correct 138 ms 16444 KB Output is correct
4 Correct 141 ms 16076 KB Output is correct
5 Correct 186 ms 18172 KB Output is correct
6 Correct 493 ms 90644 KB Output is correct
7 Correct 214 ms 22840 KB Output is correct
8 Correct 251 ms 34884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 383 ms 91348 KB Output is correct
3 Correct 1521 ms 311660 KB Output is correct
4 Correct 1542 ms 311840 KB Output is correct
5 Correct 1033 ms 188676 KB Output is correct
6 Correct 496 ms 166160 KB Output is correct
7 Correct 218 ms 97256 KB Output is correct
8 Correct 46 ms 20204 KB Output is correct
9 Correct 1340 ms 348772 KB Output is correct
10 Correct 848 ms 188792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1383 ms 609492 KB Output is correct
2 Correct 1445 ms 609800 KB Output is correct
3 Correct 235 ms 29968 KB Output is correct
4 Correct 1339 ms 609956 KB Output is correct
5 Correct 1322 ms 609972 KB Output is correct
6 Correct 204 ms 20548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 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 2 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 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 3 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 15 ms 5232 KB Output is correct
23 Correct 17 ms 6052 KB Output is correct
24 Correct 16 ms 5204 KB Output is correct
25 Correct 16 ms 5232 KB Output is correct
26 Correct 15 ms 5984 KB Output is correct
27 Correct 6 ms 1236 KB Output is correct
28 Correct 6 ms 1236 KB Output is correct
29 Correct 5 ms 1108 KB Output is correct
30 Correct 30 ms 12644 KB Output is correct
31 Correct 32 ms 11920 KB Output is correct
32 Correct 33 ms 10356 KB Output is correct
33 Correct 50 ms 6348 KB Output is correct
34 Correct 49 ms 6680 KB Output is correct
35 Correct 54 ms 6840 KB Output is correct
36 Correct 412 ms 92496 KB Output is correct
37 Correct 389 ms 92636 KB Output is correct
38 Correct 509 ms 191084 KB Output is correct
39 Correct 479 ms 19148 KB Output is correct
40 Correct 471 ms 18984 KB Output is correct
41 Correct 475 ms 18996 KB Output is correct
42 Correct 97 ms 16308 KB Output is correct
43 Correct 368 ms 154712 KB Output is correct
44 Correct 379 ms 154720 KB Output is correct
45 Correct 366 ms 154772 KB Output is correct
46 Correct 393 ms 154708 KB Output is correct
47 Correct 416 ms 154936 KB Output is correct
48 Correct 369 ms 154764 KB Output is correct
49 Correct 421 ms 154676 KB Output is correct
50 Correct 480 ms 154740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 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 2 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 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 3 ms 596 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 3 ms 596 KB Output is correct
22 Correct 15 ms 5232 KB Output is correct
23 Correct 17 ms 6052 KB Output is correct
24 Correct 16 ms 5204 KB Output is correct
25 Correct 16 ms 5232 KB Output is correct
26 Correct 15 ms 5984 KB Output is correct
27 Correct 164 ms 15844 KB Output is correct
28 Correct 142 ms 17480 KB Output is correct
29 Correct 138 ms 16444 KB Output is correct
30 Correct 141 ms 16076 KB Output is correct
31 Correct 186 ms 18172 KB Output is correct
32 Correct 493 ms 90644 KB Output is correct
33 Correct 214 ms 22840 KB Output is correct
34 Correct 251 ms 34884 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 383 ms 91348 KB Output is correct
37 Correct 1521 ms 311660 KB Output is correct
38 Correct 1542 ms 311840 KB Output is correct
39 Correct 1033 ms 188676 KB Output is correct
40 Correct 496 ms 166160 KB Output is correct
41 Correct 218 ms 97256 KB Output is correct
42 Correct 46 ms 20204 KB Output is correct
43 Correct 1340 ms 348772 KB Output is correct
44 Correct 848 ms 188792 KB Output is correct
45 Correct 1383 ms 609492 KB Output is correct
46 Correct 1445 ms 609800 KB Output is correct
47 Correct 235 ms 29968 KB Output is correct
48 Correct 1339 ms 609956 KB Output is correct
49 Correct 1322 ms 609972 KB Output is correct
50 Correct 204 ms 20548 KB Output is correct
51 Correct 6 ms 1236 KB Output is correct
52 Correct 6 ms 1236 KB Output is correct
53 Correct 5 ms 1108 KB Output is correct
54 Correct 30 ms 12644 KB Output is correct
55 Correct 32 ms 11920 KB Output is correct
56 Correct 33 ms 10356 KB Output is correct
57 Correct 50 ms 6348 KB Output is correct
58 Correct 49 ms 6680 KB Output is correct
59 Correct 54 ms 6840 KB Output is correct
60 Correct 412 ms 92496 KB Output is correct
61 Correct 389 ms 92636 KB Output is correct
62 Correct 509 ms 191084 KB Output is correct
63 Correct 479 ms 19148 KB Output is correct
64 Correct 471 ms 18984 KB Output is correct
65 Correct 475 ms 18996 KB Output is correct
66 Correct 97 ms 16308 KB Output is correct
67 Correct 368 ms 154712 KB Output is correct
68 Correct 379 ms 154720 KB Output is correct
69 Correct 366 ms 154772 KB Output is correct
70 Correct 393 ms 154708 KB Output is correct
71 Correct 416 ms 154936 KB Output is correct
72 Correct 369 ms 154764 KB Output is correct
73 Correct 421 ms 154676 KB Output is correct
74 Correct 480 ms 154740 KB Output is correct
75 Correct 168 ms 16704 KB Output is correct
76 Correct 176 ms 18216 KB Output is correct
77 Correct 148 ms 16732 KB Output is correct
78 Correct 155 ms 16344 KB Output is correct
79 Correct 335 ms 27864 KB Output is correct
80 Correct 145 ms 16420 KB Output is correct
81 Correct 1402 ms 337036 KB Output is correct
82 Correct 1332 ms 349368 KB Output is correct
83 Correct 1560 ms 312560 KB Output is correct
84 Correct 1578 ms 312448 KB Output is correct
85 Correct 1594 ms 312508 KB Output is correct
86 Correct 1346 ms 349496 KB Output is correct
87 Correct 1550 ms 312628 KB Output is correct
88 Correct 1582 ms 49316 KB Output is correct
89 Correct 1635 ms 49428 KB Output is correct
90 Correct 1674 ms 48524 KB Output is correct
91 Correct 1626 ms 49312 KB Output is correct
92 Correct 1577 ms 49392 KB Output is correct
93 Correct 1435 ms 312404 KB Output is correct
94 Correct 1263 ms 355672 KB Output is correct
95 Correct 1476 ms 318260 KB Output is correct
96 Correct 1373 ms 342980 KB Output is correct
97 Correct 1391 ms 318120 KB Output is correct
98 Correct 604 ms 114576 KB Output is correct
99 Correct 1405 ms 318424 KB Output is correct
100 Correct 1265 ms 320196 KB Output is correct
101 Correct 727 ms 116916 KB Output is correct
102 Correct 1213 ms 318452 KB Output is correct
103 Correct 1290 ms 343024 KB Output is correct
104 Correct 1200 ms 318064 KB Output is correct
105 Correct 324 ms 42388 KB Output is correct
106 Correct 804 ms 321472 KB Output is correct
107 Correct 822 ms 321484 KB Output is correct
108 Correct 784 ms 321500 KB Output is correct
109 Correct 813 ms 321268 KB Output is correct
110 Correct 811 ms 321348 KB Output is correct
111 Correct 794 ms 321500 KB Output is correct
112 Correct 848 ms 321316 KB Output is correct
113 Correct 825 ms 321384 KB Output is correct
114 Correct 821 ms 321432 KB Output is correct
115 Correct 907 ms 321492 KB Output is correct
116 Correct 830 ms 321452 KB Output is correct