Submission #51068

# Submission time Handle Problem Language Result Execution time Memory
51068 2018-06-16T02:34:12 Z edisonhello Circle selection (APIO18_circle_selection) C++11
49 / 100
3000 ms 40496 KB
#include<bits/stdc++.h>
using namespace std;

int n,pos[300005],ans[300005];
struct circle{
    int x,y,r,i;
} c[300005];

namespace std {
    template<> struct hash<pair<int,int>> {
        long long operator()(const pair<int,int> &a) const {
            return 1ll*a.first*1000000009+a.second;
        }
    };
}

unordered_map<pair<int,int>,int> mp;
vector<int> idxs[300005];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>c[i].x>>c[i].y>>c[i].r;
        c[i].i=i+1;
    }
    sort(c,c+n,[](const circle &a,const circle &b){ return a.r==b.r?a.i<b.i:a.r>b.r; });
    // for(int i=0;i<n;++i)pos[c[i].i]=i;
    int masterPtr=0;
    int D=c[0].r,killcount=0;

    auto buildGraph=[&](){
        for(int i=1;i<=int(mp.size());++i)idxs[i].clear();
        mp.clear();
        D=c[masterPtr].r;
        killcount=0;
        for(int i=masterPtr;i<n;++i){
            if(c[i].i==0)continue;
            pair<int,int> pos(c[i].x/D,c[i].y/D);
            int &it=mp[pos];
            if(it)idxs[it].push_back(i);
            else idxs[(it=mp.size())].push_back(i);
            // cout<<"insert "<<i<<" into "<<it<<" , pos: "<<pos.first<<" , "<<pos.second<<endl;
        }
    };

    buildGraph();
    while(masterPtr<n){
        while(masterPtr<n && c[masterPtr].i==0)++masterPtr;
        if(masterPtr>=n)break;
        // cout<<"now masterPtr: "<<masterPtr<<" circle is "<<c[masterPtr].i<<endl;
        // cout<<"circle position: "<<c[masterPtr].x<<" "<<c[masterPtr].y<<endl;
        if(D/c[masterPtr].r>=100 || killcount>=8000){
            buildGraph();
            // cout<<"map contains: "<<endl;
            // for(auto p:mp)cout<<"[("<<p.first.first<<" , "<<p.first.second<<") : "<<p.second<<"] ";
            // cout<<endl;
        }
        pair<int,int> pos(c[masterPtr].x/D,c[masterPtr].y/D);
        // cout<<"base position: "<<pos.first<<" "<<pos.second<<endl;
        for(int dx=-2;dx<=2;++dx){
            for(int dy=-2;dy<=2;++dy){
                auto it=mp.find(make_pair(pos.first+dx,pos.second+dy));
                if(it==mp.end())continue;
                // cout<<"it's not the end: "<<it->second<<endl;
                for(int i:idxs[it->second]){
                    if(c[i].i==0)continue;
                    if(1ll*(c[i].x-c[masterPtr].x)*(c[i].x-c[masterPtr].x)+1ll*(c[i].y-c[masterPtr].y)*(c[i].y-c[masterPtr].y)>1ll*(c[masterPtr].r+c[i].r)*(c[masterPtr].r+c[i].r))continue;
                    ans[c[i].i]=c[masterPtr].i;
                    // cout<<"killed "<<c[i].i<<", killer: "<<c[masterPtr].i<<endl;
                    
                    if(c[i].i!=c[masterPtr].i)c[i].i=0;
                    ++killcount;
                }
            }
        }
        c[masterPtr].i=0;
    }
    for(int i=1;i<=n;++i){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 9 ms 7480 KB Output is correct
3 Correct 9 ms 7588 KB Output is correct
4 Correct 8 ms 7588 KB Output is correct
5 Correct 9 ms 7588 KB Output is correct
6 Correct 8 ms 7588 KB Output is correct
7 Correct 8 ms 7588 KB Output is correct
8 Correct 9 ms 7588 KB Output is correct
9 Correct 11 ms 7588 KB Output is correct
10 Correct 8 ms 7588 KB Output is correct
11 Correct 10 ms 7588 KB Output is correct
12 Correct 8 ms 7588 KB Output is correct
13 Correct 11 ms 7588 KB Output is correct
14 Correct 10 ms 7704 KB Output is correct
15 Correct 7 ms 7704 KB Output is correct
16 Correct 9 ms 7704 KB Output is correct
17 Correct 9 ms 7704 KB Output is correct
18 Correct 9 ms 7704 KB Output is correct
19 Correct 11 ms 7808 KB Output is correct
20 Correct 11 ms 7808 KB Output is correct
21 Correct 13 ms 7808 KB Output is correct
22 Correct 21 ms 8204 KB Output is correct
23 Correct 21 ms 8220 KB Output is correct
24 Correct 22 ms 8220 KB Output is correct
25 Correct 19 ms 8272 KB Output is correct
26 Correct 19 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 16972 KB Output is correct
2 Correct 240 ms 17648 KB Output is correct
3 Correct 229 ms 17648 KB Output is correct
4 Correct 215 ms 17648 KB Output is correct
5 Correct 603 ms 18264 KB Output is correct
6 Correct 2590 ms 29048 KB Output is correct
7 Correct 707 ms 29048 KB Output is correct
8 Correct 962 ms 29048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29048 KB Output is correct
2 Correct 676 ms 29048 KB Output is correct
3 Execution timed out 3054 ms 40496 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 40496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 9 ms 7480 KB Output is correct
3 Correct 9 ms 7588 KB Output is correct
4 Correct 8 ms 7588 KB Output is correct
5 Correct 9 ms 7588 KB Output is correct
6 Correct 8 ms 7588 KB Output is correct
7 Correct 8 ms 7588 KB Output is correct
8 Correct 9 ms 7588 KB Output is correct
9 Correct 11 ms 7588 KB Output is correct
10 Correct 8 ms 7588 KB Output is correct
11 Correct 10 ms 7588 KB Output is correct
12 Correct 8 ms 7588 KB Output is correct
13 Correct 11 ms 7588 KB Output is correct
14 Correct 10 ms 7704 KB Output is correct
15 Correct 7 ms 7704 KB Output is correct
16 Correct 9 ms 7704 KB Output is correct
17 Correct 9 ms 7704 KB Output is correct
18 Correct 9 ms 7704 KB Output is correct
19 Correct 11 ms 7808 KB Output is correct
20 Correct 11 ms 7808 KB Output is correct
21 Correct 13 ms 7808 KB Output is correct
22 Correct 21 ms 8204 KB Output is correct
23 Correct 21 ms 8220 KB Output is correct
24 Correct 22 ms 8220 KB Output is correct
25 Correct 19 ms 8272 KB Output is correct
26 Correct 19 ms 8272 KB Output is correct
27 Correct 16 ms 40496 KB Output is correct
28 Correct 17 ms 40496 KB Output is correct
29 Correct 16 ms 40496 KB Output is correct
30 Correct 36 ms 40496 KB Output is correct
31 Correct 42 ms 40496 KB Output is correct
32 Correct 31 ms 40496 KB Output is correct
33 Correct 83 ms 40496 KB Output is correct
34 Correct 74 ms 40496 KB Output is correct
35 Correct 77 ms 40496 KB Output is correct
36 Correct 528 ms 40496 KB Output is correct
37 Correct 547 ms 40496 KB Output is correct
38 Correct 582 ms 40496 KB Output is correct
39 Correct 445 ms 40496 KB Output is correct
40 Correct 395 ms 40496 KB Output is correct
41 Correct 424 ms 40496 KB Output is correct
42 Correct 425 ms 40496 KB Output is correct
43 Correct 477 ms 40496 KB Output is correct
44 Correct 510 ms 40496 KB Output is correct
45 Correct 497 ms 40496 KB Output is correct
46 Correct 487 ms 40496 KB Output is correct
47 Correct 469 ms 40496 KB Output is correct
48 Correct 500 ms 40496 KB Output is correct
49 Correct 613 ms 40496 KB Output is correct
50 Correct 444 ms 40496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 9 ms 7480 KB Output is correct
3 Correct 9 ms 7588 KB Output is correct
4 Correct 8 ms 7588 KB Output is correct
5 Correct 9 ms 7588 KB Output is correct
6 Correct 8 ms 7588 KB Output is correct
7 Correct 8 ms 7588 KB Output is correct
8 Correct 9 ms 7588 KB Output is correct
9 Correct 11 ms 7588 KB Output is correct
10 Correct 8 ms 7588 KB Output is correct
11 Correct 10 ms 7588 KB Output is correct
12 Correct 8 ms 7588 KB Output is correct
13 Correct 11 ms 7588 KB Output is correct
14 Correct 10 ms 7704 KB Output is correct
15 Correct 7 ms 7704 KB Output is correct
16 Correct 9 ms 7704 KB Output is correct
17 Correct 9 ms 7704 KB Output is correct
18 Correct 9 ms 7704 KB Output is correct
19 Correct 11 ms 7808 KB Output is correct
20 Correct 11 ms 7808 KB Output is correct
21 Correct 13 ms 7808 KB Output is correct
22 Correct 21 ms 8204 KB Output is correct
23 Correct 21 ms 8220 KB Output is correct
24 Correct 22 ms 8220 KB Output is correct
25 Correct 19 ms 8272 KB Output is correct
26 Correct 19 ms 8272 KB Output is correct
27 Correct 192 ms 16972 KB Output is correct
28 Correct 240 ms 17648 KB Output is correct
29 Correct 229 ms 17648 KB Output is correct
30 Correct 215 ms 17648 KB Output is correct
31 Correct 603 ms 18264 KB Output is correct
32 Correct 2590 ms 29048 KB Output is correct
33 Correct 707 ms 29048 KB Output is correct
34 Correct 962 ms 29048 KB Output is correct
35 Correct 9 ms 29048 KB Output is correct
36 Correct 676 ms 29048 KB Output is correct
37 Execution timed out 3054 ms 40496 KB Time limit exceeded
38 Halted 0 ms 0 KB -