Submission #250926

# Submission time Handle Problem Language Result Execution time Memory
250926 2020-07-19T13:03:35 Z nvmdava Circle selection (APIO18_circle_selection) C++17
100 / 100
2864 ms 50728 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 300005
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;

int x[N], y[N], r[N];
int lr = 2'000'000'002;
int ans[N];
int n;

vector<pair<int, int> > v;

map<pair<int, int>, vector<int> > id;

inline ll pw(ll a){
    return a * a;
}

bool check(int i, int j){
    return pw(x[i] - x[j]) + pw(y[i] - y[j]) <= pw(r[i] + r[j]);
}

inline int divv(int a, int b){
    return a / b + (a < 0 && a % b != 0);
}

void reset(int r){
    id.clear();
    for(int i = 1; i <= n; ++i){
        if(ans[i]) continue;
        int xx = divv(x[i], r);
        int yy = divv(y[i], r);
        id[{xx, yy}].push_back(i);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin>>n;
    for(int i = 1; i <= n; ++i){
        cin>>x[i]>>y[i]>>r[i];
        v.push_back({-r[i], i});
    }


    sort(v.begin(), v.end());

    for(auto& w : v){
        if(ans[w.ss]) continue;
        if(lr >= 2 * r[w.ss])
            reset(lr = r[w.ss]);
        int xx = divv(x[w.ss], lr);
        int yy = divv(y[w.ss], lr);
        for(int dx = -3; dx <= 3; ++dx){
            for(int dy = -3; dy <= 3; ++dy){
                auto it = id.find({xx + dx, yy + dy});
                if(it == id.end()) continue;
                for(int i = 0; i < it -> ss.size(); ++i){
                    if(check(it -> ss[i], w.ss)){
                        ans[it -> ss[i]] = w.ss;
                        swap(it -> ss[i], it -> ss.back());
                        it -> ss.pop_back();
                        --i;
                    }
                }
                if(it -> ss.empty())
                    id.erase(it);

            }
        }
    }

    for(int i = 1; i <= n; ++i)
        cout<<ans[i]<<' ';
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:66:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i = 0; i < it -> ss.size(); ++i){
                                ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 20 ms 1088 KB Output is correct
24 Correct 15 ms 1100 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 16 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 11748 KB Output is correct
2 Correct 172 ms 12116 KB Output is correct
3 Correct 165 ms 11616 KB Output is correct
4 Correct 172 ms 11360 KB Output is correct
5 Correct 241 ms 11980 KB Output is correct
6 Correct 866 ms 25668 KB Output is correct
7 Correct 271 ms 13552 KB Output is correct
8 Correct 371 ms 15716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 692 ms 14348 KB Output is correct
3 Correct 2321 ms 42336 KB Output is correct
4 Correct 2353 ms 42268 KB Output is correct
5 Correct 2191 ms 36096 KB Output is correct
6 Correct 679 ms 17640 KB Output is correct
7 Correct 272 ms 9712 KB Output is correct
8 Correct 36 ms 2424 KB Output is correct
9 Correct 2549 ms 41344 KB Output is correct
10 Correct 1933 ms 34584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1755 ms 42464 KB Output is correct
2 Correct 1171 ms 42592 KB Output is correct
3 Correct 462 ms 19040 KB Output is correct
4 Correct 1277 ms 42424 KB Output is correct
5 Correct 1285 ms 42336 KB Output is correct
6 Correct 269 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 20 ms 1088 KB Output is correct
24 Correct 15 ms 1100 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 16 ms 1024 KB Output is correct
27 Correct 7 ms 768 KB Output is correct
28 Correct 7 ms 768 KB Output is correct
29 Correct 7 ms 768 KB Output is correct
30 Correct 38 ms 1784 KB Output is correct
31 Correct 33 ms 1784 KB Output is correct
32 Correct 35 ms 1784 KB Output is correct
33 Correct 67 ms 4216 KB Output is correct
34 Correct 65 ms 3568 KB Output is correct
35 Correct 69 ms 3952 KB Output is correct
36 Correct 514 ms 14304 KB Output is correct
37 Correct 499 ms 14320 KB Output is correct
38 Correct 527 ms 14320 KB Output is correct
39 Correct 332 ms 12656 KB Output is correct
40 Correct 397 ms 12708 KB Output is correct
41 Correct 322 ms 12780 KB Output is correct
42 Correct 231 ms 14192 KB Output is correct
43 Correct 309 ms 13992 KB Output is correct
44 Correct 326 ms 14064 KB Output is correct
45 Correct 334 ms 16756 KB Output is correct
46 Correct 305 ms 16616 KB Output is correct
47 Correct 310 ms 16728 KB Output is correct
48 Correct 326 ms 16748 KB Output is correct
49 Correct 335 ms 16624 KB Output is correct
50 Correct 331 ms 16608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 3 ms 640 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 17 ms 1024 KB Output is correct
23 Correct 20 ms 1088 KB Output is correct
24 Correct 15 ms 1100 KB Output is correct
25 Correct 14 ms 1024 KB Output is correct
26 Correct 16 ms 1024 KB Output is correct
27 Correct 186 ms 11748 KB Output is correct
28 Correct 172 ms 12116 KB Output is correct
29 Correct 165 ms 11616 KB Output is correct
30 Correct 172 ms 11360 KB Output is correct
31 Correct 241 ms 11980 KB Output is correct
32 Correct 866 ms 25668 KB Output is correct
33 Correct 271 ms 13552 KB Output is correct
34 Correct 371 ms 15716 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 692 ms 14348 KB Output is correct
37 Correct 2321 ms 42336 KB Output is correct
38 Correct 2353 ms 42268 KB Output is correct
39 Correct 2191 ms 36096 KB Output is correct
40 Correct 679 ms 17640 KB Output is correct
41 Correct 272 ms 9712 KB Output is correct
42 Correct 36 ms 2424 KB Output is correct
43 Correct 2549 ms 41344 KB Output is correct
44 Correct 1933 ms 34584 KB Output is correct
45 Correct 1755 ms 42464 KB Output is correct
46 Correct 1171 ms 42592 KB Output is correct
47 Correct 462 ms 19040 KB Output is correct
48 Correct 1277 ms 42424 KB Output is correct
49 Correct 1285 ms 42336 KB Output is correct
50 Correct 269 ms 12772 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
52 Correct 7 ms 768 KB Output is correct
53 Correct 7 ms 768 KB Output is correct
54 Correct 38 ms 1784 KB Output is correct
55 Correct 33 ms 1784 KB Output is correct
56 Correct 35 ms 1784 KB Output is correct
57 Correct 67 ms 4216 KB Output is correct
58 Correct 65 ms 3568 KB Output is correct
59 Correct 69 ms 3952 KB Output is correct
60 Correct 514 ms 14304 KB Output is correct
61 Correct 499 ms 14320 KB Output is correct
62 Correct 527 ms 14320 KB Output is correct
63 Correct 332 ms 12656 KB Output is correct
64 Correct 397 ms 12708 KB Output is correct
65 Correct 322 ms 12780 KB Output is correct
66 Correct 231 ms 14192 KB Output is correct
67 Correct 309 ms 13992 KB Output is correct
68 Correct 326 ms 14064 KB Output is correct
69 Correct 334 ms 16756 KB Output is correct
70 Correct 305 ms 16616 KB Output is correct
71 Correct 310 ms 16728 KB Output is correct
72 Correct 326 ms 16748 KB Output is correct
73 Correct 335 ms 16624 KB Output is correct
74 Correct 331 ms 16608 KB Output is correct
75 Correct 219 ms 20368 KB Output is correct
76 Correct 205 ms 20696 KB Output is correct
77 Correct 197 ms 20840 KB Output is correct
78 Correct 195 ms 20324 KB Output is correct
79 Correct 232 ms 20172 KB Output is correct
80 Correct 196 ms 19684 KB Output is correct
81 Correct 2221 ms 50320 KB Output is correct
82 Correct 2264 ms 50156 KB Output is correct
83 Correct 2187 ms 50188 KB Output is correct
84 Correct 2477 ms 50728 KB Output is correct
85 Correct 2408 ms 50180 KB Output is correct
86 Correct 2194 ms 50320 KB Output is correct
87 Correct 2864 ms 50144 KB Output is correct
88 Correct 1270 ms 40800 KB Output is correct
89 Correct 1447 ms 40860 KB Output is correct
90 Correct 1319 ms 40952 KB Output is correct
91 Correct 1503 ms 40800 KB Output is correct
92 Correct 1256 ms 40796 KB Output is correct
93 Correct 1464 ms 49248 KB Output is correct
94 Correct 1872 ms 49504 KB Output is correct
95 Correct 1523 ms 49252 KB Output is correct
96 Correct 1553 ms 49216 KB Output is correct
97 Correct 2782 ms 49120 KB Output is correct
98 Correct 932 ms 37676 KB Output is correct
99 Correct 1519 ms 49376 KB Output is correct
100 Correct 1513 ms 49116 KB Output is correct
101 Correct 1360 ms 42592 KB Output is correct
102 Correct 1525 ms 48868 KB Output is correct
103 Correct 2402 ms 48776 KB Output is correct
104 Correct 1736 ms 49060 KB Output is correct
105 Correct 1020 ms 46948 KB Output is correct
106 Correct 1164 ms 47856 KB Output is correct
107 Correct 1074 ms 47968 KB Output is correct
108 Correct 1086 ms 48152 KB Output is correct
109 Correct 1218 ms 47928 KB Output is correct
110 Correct 1085 ms 47948 KB Output is correct
111 Correct 1192 ms 48076 KB Output is correct
112 Correct 1066 ms 47888 KB Output is correct
113 Correct 1127 ms 47964 KB Output is correct
114 Correct 1112 ms 47996 KB Output is correct
115 Correct 1070 ms 48000 KB Output is correct
116 Correct 1044 ms 47924 KB Output is correct