답안 #658358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658358 2022-11-12T21:51:15 Z Richem 원 고르기 (APIO18_circle_selection) C++14
100 / 100
2660 ms 1014712 KB
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <time.h>
#pragma once
#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{
    unsigned int 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, vector<int>> grille;
bool enleve[MAX_CERCLE] = {0};
 
int quiEnleve[MAX_CERCLE];
 
unsigned int tailleGrille = (1 << 31);
 
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 = (long long)cercle[cur].xCentre / tailleGrille;
                int yGrille = cercle[cur].yCentre / tailleGrille;
                
                grille[(xGrille << 32) + yGrille].push_back(cur);
            }
        }
 
        long long xGrille = (long long)cercle[grand].xCentre / tailleGrille, yGrille = (long long)cercle[grand].yCentre / tailleGrille;
 
        vector<int> quiReste;
        for(int deltaX = -2; deltaX <= 2; deltaX++) {
            for(int deltaY = -2; deltaY <= 2; deltaY++) {
                long long nouvX = xGrille + deltaX, nouvY = yGrille + deltaY;
                auto &v = grille[(nouvX << 32) + nouvY];
 
                //for(int type = 0; type < 2; type++) {
 
                    for(int id = v.size()-1; id >= 0; id--) {
                        int autre = v[id];
                        
                        long long xDist = (long long)cercle[grand].xCentre - cercle[autre].xCentre, yDist = (long long)cercle[grand].yCentre - cercle[autre].yCentre;
                        long long rDist = (long long)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;
                            
                            swap(v[id], v[v.size()-1]);
                            v.pop_back();
                        }
                    }
               // }
            }
        }
 
        for(auto nouveau : quiReste) {
            if(enleve[nouveau])
                continue;
            long long xGrille = (long long)cercle[nouveau].xCentre / tailleGrille;
            int yGrille = cercle[nouveau].yCentre / tailleGrille;
            
            grille[(xGrille << 32) + yGrille].push_back(nouveau);
        }
    }
 
    for(int cur = 0; cur < nbCercle; cur++) {
        cout << quiEnleve[cur]+1 << " ";
    }
}
/*
11
9 9 2
13 2 1 11 8 2 3 3 2 3 12 1 12 14 1 9 8 5 2 8 2 5 2 1 14 4 2 14 14 1
*/

Compilation message

circle_selection.cpp:6:9: warning: #pragma once in main file
    6 | #pragma once
      |         ^~~~
# 결과 실행 시간 메모리 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 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 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 596 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 396 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 3 ms 584 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 25 ms 9692 KB Output is correct
23 Correct 24 ms 11552 KB Output is correct
24 Correct 29 ms 9744 KB Output is correct
25 Correct 26 ms 9692 KB Output is correct
26 Correct 24 ms 11568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 12088 KB Output is correct
2 Correct 133 ms 10704 KB Output is correct
3 Correct 127 ms 11216 KB Output is correct
4 Correct 126 ms 11152 KB Output is correct
5 Correct 157 ms 14172 KB Output is correct
6 Correct 756 ms 155464 KB Output is correct
7 Correct 198 ms 20080 KB Output is correct
8 Correct 293 ms 41868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 679 ms 151664 KB Output is correct
3 Correct 2596 ms 518612 KB Output is correct
4 Correct 2577 ms 519116 KB Output is correct
5 Correct 1944 ms 539388 KB Output is correct
6 Correct 667 ms 167344 KB Output is correct
7 Correct 403 ms 146820 KB Output is correct
8 Correct 76 ms 32712 KB Output is correct
9 Correct 2660 ms 537724 KB Output is correct
10 Correct 1416 ms 293396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2229 ms 1014712 KB Output is correct
2 Correct 2163 ms 1013168 KB Output is correct
3 Correct 219 ms 19752 KB Output is correct
4 Correct 2198 ms 1012988 KB Output is correct
5 Correct 2360 ms 1013392 KB Output is correct
6 Correct 177 ms 13504 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 596 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 396 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 3 ms 584 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 25 ms 9692 KB Output is correct
23 Correct 24 ms 11552 KB Output is correct
24 Correct 29 ms 9744 KB Output is correct
25 Correct 26 ms 9692 KB Output is correct
26 Correct 24 ms 11568 KB Output is correct
27 Correct 6 ms 992 KB Output is correct
28 Correct 6 ms 928 KB Output is correct
29 Correct 5 ms 980 KB Output is correct
30 Correct 65 ms 19116 KB Output is correct
31 Correct 52 ms 21128 KB Output is correct
32 Correct 70 ms 19164 KB Output is correct
33 Correct 52 ms 6376 KB Output is correct
34 Correct 49 ms 6056 KB Output is correct
35 Correct 62 ms 5632 KB Output is correct
36 Correct 942 ms 255464 KB Output is correct
37 Correct 735 ms 152040 KB Output is correct
38 Correct 938 ms 254900 KB Output is correct
39 Correct 297 ms 69700 KB Output is correct
40 Correct 310 ms 69652 KB Output is correct
41 Correct 294 ms 69608 KB Output is correct
42 Correct 96 ms 13136 KB Output is correct
43 Correct 954 ms 503056 KB Output is correct
44 Correct 950 ms 503008 KB Output is correct
45 Correct 924 ms 503000 KB Output is correct
46 Correct 922 ms 503052 KB Output is correct
47 Correct 962 ms 503048 KB Output is correct
48 Correct 884 ms 502964 KB Output is correct
49 Correct 901 ms 503060 KB Output is correct
50 Correct 923 ms 503056 KB Output is correct
# 결과 실행 시간 메모리 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 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 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 596 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 396 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 3 ms 584 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 25 ms 9692 KB Output is correct
23 Correct 24 ms 11552 KB Output is correct
24 Correct 29 ms 9744 KB Output is correct
25 Correct 26 ms 9692 KB Output is correct
26 Correct 24 ms 11568 KB Output is correct
27 Correct 133 ms 12088 KB Output is correct
28 Correct 133 ms 10704 KB Output is correct
29 Correct 127 ms 11216 KB Output is correct
30 Correct 126 ms 11152 KB Output is correct
31 Correct 157 ms 14172 KB Output is correct
32 Correct 756 ms 155464 KB Output is correct
33 Correct 198 ms 20080 KB Output is correct
34 Correct 293 ms 41868 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 679 ms 151664 KB Output is correct
37 Correct 2596 ms 518612 KB Output is correct
38 Correct 2577 ms 519116 KB Output is correct
39 Correct 1944 ms 539388 KB Output is correct
40 Correct 667 ms 167344 KB Output is correct
41 Correct 403 ms 146820 KB Output is correct
42 Correct 76 ms 32712 KB Output is correct
43 Correct 2660 ms 537724 KB Output is correct
44 Correct 1416 ms 293396 KB Output is correct
45 Correct 2229 ms 1014712 KB Output is correct
46 Correct 2163 ms 1013168 KB Output is correct
47 Correct 219 ms 19752 KB Output is correct
48 Correct 2198 ms 1012988 KB Output is correct
49 Correct 2360 ms 1013392 KB Output is correct
50 Correct 177 ms 13504 KB Output is correct
51 Correct 6 ms 992 KB Output is correct
52 Correct 6 ms 928 KB Output is correct
53 Correct 5 ms 980 KB Output is correct
54 Correct 65 ms 19116 KB Output is correct
55 Correct 52 ms 21128 KB Output is correct
56 Correct 70 ms 19164 KB Output is correct
57 Correct 52 ms 6376 KB Output is correct
58 Correct 49 ms 6056 KB Output is correct
59 Correct 62 ms 5632 KB Output is correct
60 Correct 942 ms 255464 KB Output is correct
61 Correct 735 ms 152040 KB Output is correct
62 Correct 938 ms 254900 KB Output is correct
63 Correct 297 ms 69700 KB Output is correct
64 Correct 310 ms 69652 KB Output is correct
65 Correct 294 ms 69608 KB Output is correct
66 Correct 96 ms 13136 KB Output is correct
67 Correct 954 ms 503056 KB Output is correct
68 Correct 950 ms 503008 KB Output is correct
69 Correct 924 ms 503000 KB Output is correct
70 Correct 922 ms 503052 KB Output is correct
71 Correct 962 ms 503048 KB Output is correct
72 Correct 884 ms 502964 KB Output is correct
73 Correct 901 ms 503060 KB Output is correct
74 Correct 923 ms 503056 KB Output is correct
75 Correct 159 ms 10652 KB Output is correct
76 Correct 149 ms 10256 KB Output is correct
77 Correct 155 ms 11704 KB Output is correct
78 Correct 149 ms 11000 KB Output is correct
79 Correct 179 ms 11160 KB Output is correct
80 Correct 135 ms 11028 KB Output is correct
81 Correct 2231 ms 537536 KB Output is correct
82 Correct 2352 ms 519296 KB Output is correct
83 Correct 2624 ms 519024 KB Output is correct
84 Correct 2570 ms 519120 KB Output is correct
85 Correct 2569 ms 519268 KB Output is correct
86 Correct 2491 ms 519068 KB Output is correct
87 Correct 2450 ms 518932 KB Output is correct
88 Correct 773 ms 148992 KB Output is correct
89 Correct 783 ms 148920 KB Output is correct
90 Correct 781 ms 149088 KB Output is correct
91 Correct 778 ms 148872 KB Output is correct
92 Correct 789 ms 148884 KB Output is correct
93 Correct 2276 ms 519244 KB Output is correct
94 Correct 1979 ms 518988 KB Output is correct
95 Correct 2303 ms 519292 KB Output is correct
96 Correct 2033 ms 519148 KB Output is correct
97 Correct 2577 ms 519228 KB Output is correct
98 Correct 839 ms 170376 KB Output is correct
99 Correct 2545 ms 519232 KB Output is correct
100 Correct 2051 ms 518988 KB Output is correct
101 Correct 1014 ms 170232 KB Output is correct
102 Correct 2441 ms 518556 KB Output is correct
103 Correct 2122 ms 537652 KB Output is correct
104 Correct 2438 ms 519252 KB Output is correct
105 Correct 352 ms 48644 KB Output is correct
106 Correct 1884 ms 1012036 KB Output is correct
107 Correct 1918 ms 1012776 KB Output is correct
108 Correct 1923 ms 1012716 KB Output is correct
109 Correct 1972 ms 1012844 KB Output is correct
110 Correct 1849 ms 1013188 KB Output is correct
111 Correct 1899 ms 1013076 KB Output is correct
112 Correct 1862 ms 1013068 KB Output is correct
113 Correct 2024 ms 1013056 KB Output is correct
114 Correct 1966 ms 1013060 KB Output is correct
115 Correct 1905 ms 1013004 KB Output is correct
116 Correct 1883 ms 1013108 KB Output is correct