Submission #250922

# Submission time Handle Problem Language Result Execution time Memory
250922 2020-07-19T12:50:03 Z nvmdava Circle selection (APIO18_circle_selection) C++17
57 / 100
2252 ms 50524 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 = -2; dx <= 2; ++dx){
            for(int dy = -2; dy <= 2; ++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:65: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 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 404 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 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 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 13 ms 1152 KB Output is correct
23 Correct 15 ms 1152 KB Output is correct
24 Correct 13 ms 1152 KB Output is correct
25 Correct 12 ms 1152 KB Output is correct
26 Correct 13 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 18348 KB Output is correct
2 Correct 176 ms 18916 KB Output is correct
3 Correct 175 ms 18276 KB Output is correct
4 Correct 172 ms 18124 KB Output is correct
5 Correct 249 ms 16608 KB Output is correct
6 Correct 836 ms 30212 KB Output is correct
7 Correct 267 ms 18416 KB Output is correct
8 Correct 384 ms 20452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 517 ms 17004 KB Output is correct
3 Correct 2252 ms 50524 KB Output is correct
4 Correct 2087 ms 50372 KB Output is correct
5 Correct 2059 ms 43996 KB Output is correct
6 Correct 621 ms 22120 KB Output is correct
7 Correct 236 ms 12016 KB Output is correct
8 Correct 32 ms 2936 KB Output is correct
9 Correct 2233 ms 49508 KB Output is correct
10 Correct 1738 ms 42912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1463 ms 50164 KB Output is correct
2 Correct 1000 ms 49396 KB Output is correct
3 Correct 488 ms 27584 KB Output is correct
4 Correct 1491 ms 49784 KB Output is correct
5 Correct 1068 ms 50328 KB Output is correct
6 Correct 267 ms 21216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 404 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 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 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 13 ms 1152 KB Output is correct
23 Correct 15 ms 1152 KB Output is correct
24 Correct 13 ms 1152 KB Output is correct
25 Correct 12 ms 1152 KB Output is correct
26 Correct 13 ms 1152 KB Output is correct
27 Correct 7 ms 1152 KB Output is correct
28 Correct 7 ms 1152 KB Output is correct
29 Correct 7 ms 1152 KB Output is correct
30 Correct 32 ms 2040 KB Output is correct
31 Correct 27 ms 2048 KB Output is correct
32 Correct 27 ms 2040 KB Output is correct
33 Correct 67 ms 7148 KB Output is correct
34 Correct 70 ms 6764 KB Output is correct
35 Correct 70 ms 6896 KB Output is correct
36 Correct 394 ms 16752 KB Output is correct
37 Correct 409 ms 17004 KB Output is correct
38 Correct 410 ms 17008 KB Output is correct
39 Correct 265 ms 13772 KB Output is correct
40 Correct 267 ms 13804 KB Output is correct
41 Correct 304 ms 13996 KB Output is correct
42 Correct 229 ms 15856 KB Output is correct
43 Correct 269 ms 16604 KB Output is correct
44 Incorrect 246 ms 16684 KB Output isn't correct
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 404 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 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 4 ms 768 KB Output is correct
20 Correct 3 ms 768 KB Output is correct
21 Correct 4 ms 768 KB Output is correct
22 Correct 13 ms 1152 KB Output is correct
23 Correct 15 ms 1152 KB Output is correct
24 Correct 13 ms 1152 KB Output is correct
25 Correct 12 ms 1152 KB Output is correct
26 Correct 13 ms 1152 KB Output is correct
27 Correct 178 ms 18348 KB Output is correct
28 Correct 176 ms 18916 KB Output is correct
29 Correct 175 ms 18276 KB Output is correct
30 Correct 172 ms 18124 KB Output is correct
31 Correct 249 ms 16608 KB Output is correct
32 Correct 836 ms 30212 KB Output is correct
33 Correct 267 ms 18416 KB Output is correct
34 Correct 384 ms 20452 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 517 ms 17004 KB Output is correct
37 Correct 2252 ms 50524 KB Output is correct
38 Correct 2087 ms 50372 KB Output is correct
39 Correct 2059 ms 43996 KB Output is correct
40 Correct 621 ms 22120 KB Output is correct
41 Correct 236 ms 12016 KB Output is correct
42 Correct 32 ms 2936 KB Output is correct
43 Correct 2233 ms 49508 KB Output is correct
44 Correct 1738 ms 42912 KB Output is correct
45 Correct 1463 ms 50164 KB Output is correct
46 Correct 1000 ms 49396 KB Output is correct
47 Correct 488 ms 27584 KB Output is correct
48 Correct 1491 ms 49784 KB Output is correct
49 Correct 1068 ms 50328 KB Output is correct
50 Correct 267 ms 21216 KB Output is correct
51 Correct 7 ms 1152 KB Output is correct
52 Correct 7 ms 1152 KB Output is correct
53 Correct 7 ms 1152 KB Output is correct
54 Correct 32 ms 2040 KB Output is correct
55 Correct 27 ms 2048 KB Output is correct
56 Correct 27 ms 2040 KB Output is correct
57 Correct 67 ms 7148 KB Output is correct
58 Correct 70 ms 6764 KB Output is correct
59 Correct 70 ms 6896 KB Output is correct
60 Correct 394 ms 16752 KB Output is correct
61 Correct 409 ms 17004 KB Output is correct
62 Correct 410 ms 17008 KB Output is correct
63 Correct 265 ms 13772 KB Output is correct
64 Correct 267 ms 13804 KB Output is correct
65 Correct 304 ms 13996 KB Output is correct
66 Correct 229 ms 15856 KB Output is correct
67 Correct 269 ms 16604 KB Output is correct
68 Incorrect 246 ms 16684 KB Output isn't correct
69 Halted 0 ms 0 KB -