Submission #51070

# Submission time Handle Problem Language Result Execution time Memory
51070 2018-06-16T02:42:10 Z edisonhello Circle selection (APIO18_circle_selection) C++11
49 / 100
3000 ms 40548 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,tune=native")
#include<cstdio>
#include<unordered_map>
#include<vector>
#include<utility>
#include<algorithm>
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 rit(){
    char c; int x=0; bool mi=0;
    while((c=getchar_unlocked())){ if(c=='-' || (c>='0' && c<='9'))break; }
    if(c=='-')mi=1;
    else x=c-'0';
    while((c=getchar_unlocked())){ if(c<'0' || c>'9')break; x=x*10+(c&15); }
    return mi?-x:x;
}

int main(){
    n=rit();
    for(int i=0;i<n;++i){
        c[i].x=rit(),c[i].y=rit(),c[i].r=rit();
        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){
        printf("%d ",ans[i]);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7596 KB Output is correct
4 Correct 8 ms 7596 KB Output is correct
5 Correct 8 ms 7596 KB Output is correct
6 Correct 8 ms 7596 KB Output is correct
7 Correct 8 ms 7596 KB Output is correct
8 Correct 8 ms 7624 KB Output is correct
9 Correct 8 ms 7624 KB Output is correct
10 Correct 8 ms 7624 KB Output is correct
11 Correct 8 ms 7636 KB Output is correct
12 Correct 8 ms 7636 KB Output is correct
13 Correct 8 ms 7636 KB Output is correct
14 Correct 8 ms 7636 KB Output is correct
15 Correct 8 ms 7636 KB Output is correct
16 Correct 8 ms 7760 KB Output is correct
17 Correct 8 ms 7760 KB Output is correct
18 Correct 8 ms 7760 KB Output is correct
19 Correct 10 ms 7760 KB Output is correct
20 Correct 9 ms 7760 KB Output is correct
21 Correct 10 ms 7772 KB Output is correct
22 Correct 18 ms 8144 KB Output is correct
23 Correct 17 ms 8172 KB Output is correct
24 Correct 18 ms 8188 KB Output is correct
25 Correct 19 ms 8316 KB Output is correct
26 Correct 17 ms 8316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 16812 KB Output is correct
2 Correct 146 ms 17520 KB Output is correct
3 Correct 144 ms 17520 KB Output is correct
4 Correct 156 ms 17520 KB Output is correct
5 Correct 615 ms 18272 KB Output is correct
6 Correct 2100 ms 29016 KB Output is correct
7 Correct 730 ms 29016 KB Output is correct
8 Correct 1079 ms 29016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29016 KB Output is correct
2 Correct 413 ms 29016 KB Output is correct
3 Execution timed out 3045 ms 40548 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 40548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7596 KB Output is correct
4 Correct 8 ms 7596 KB Output is correct
5 Correct 8 ms 7596 KB Output is correct
6 Correct 8 ms 7596 KB Output is correct
7 Correct 8 ms 7596 KB Output is correct
8 Correct 8 ms 7624 KB Output is correct
9 Correct 8 ms 7624 KB Output is correct
10 Correct 8 ms 7624 KB Output is correct
11 Correct 8 ms 7636 KB Output is correct
12 Correct 8 ms 7636 KB Output is correct
13 Correct 8 ms 7636 KB Output is correct
14 Correct 8 ms 7636 KB Output is correct
15 Correct 8 ms 7636 KB Output is correct
16 Correct 8 ms 7760 KB Output is correct
17 Correct 8 ms 7760 KB Output is correct
18 Correct 8 ms 7760 KB Output is correct
19 Correct 10 ms 7760 KB Output is correct
20 Correct 9 ms 7760 KB Output is correct
21 Correct 10 ms 7772 KB Output is correct
22 Correct 18 ms 8144 KB Output is correct
23 Correct 17 ms 8172 KB Output is correct
24 Correct 18 ms 8188 KB Output is correct
25 Correct 19 ms 8316 KB Output is correct
26 Correct 17 ms 8316 KB Output is correct
27 Correct 12 ms 40548 KB Output is correct
28 Correct 11 ms 40548 KB Output is correct
29 Correct 12 ms 40548 KB Output is correct
30 Correct 27 ms 40548 KB Output is correct
31 Correct 26 ms 40548 KB Output is correct
32 Correct 27 ms 40548 KB Output is correct
33 Correct 52 ms 40548 KB Output is correct
34 Correct 50 ms 40548 KB Output is correct
35 Correct 53 ms 40548 KB Output is correct
36 Correct 443 ms 40548 KB Output is correct
37 Correct 490 ms 40548 KB Output is correct
38 Correct 479 ms 40548 KB Output is correct
39 Correct 438 ms 40548 KB Output is correct
40 Correct 430 ms 40548 KB Output is correct
41 Correct 384 ms 40548 KB Output is correct
42 Correct 438 ms 40548 KB Output is correct
43 Correct 432 ms 40548 KB Output is correct
44 Correct 424 ms 40548 KB Output is correct
45 Correct 411 ms 40548 KB Output is correct
46 Correct 417 ms 40548 KB Output is correct
47 Correct 431 ms 40548 KB Output is correct
48 Correct 425 ms 40548 KB Output is correct
49 Correct 435 ms 40548 KB Output is correct
50 Correct 443 ms 40548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7596 KB Output is correct
4 Correct 8 ms 7596 KB Output is correct
5 Correct 8 ms 7596 KB Output is correct
6 Correct 8 ms 7596 KB Output is correct
7 Correct 8 ms 7596 KB Output is correct
8 Correct 8 ms 7624 KB Output is correct
9 Correct 8 ms 7624 KB Output is correct
10 Correct 8 ms 7624 KB Output is correct
11 Correct 8 ms 7636 KB Output is correct
12 Correct 8 ms 7636 KB Output is correct
13 Correct 8 ms 7636 KB Output is correct
14 Correct 8 ms 7636 KB Output is correct
15 Correct 8 ms 7636 KB Output is correct
16 Correct 8 ms 7760 KB Output is correct
17 Correct 8 ms 7760 KB Output is correct
18 Correct 8 ms 7760 KB Output is correct
19 Correct 10 ms 7760 KB Output is correct
20 Correct 9 ms 7760 KB Output is correct
21 Correct 10 ms 7772 KB Output is correct
22 Correct 18 ms 8144 KB Output is correct
23 Correct 17 ms 8172 KB Output is correct
24 Correct 18 ms 8188 KB Output is correct
25 Correct 19 ms 8316 KB Output is correct
26 Correct 17 ms 8316 KB Output is correct
27 Correct 136 ms 16812 KB Output is correct
28 Correct 146 ms 17520 KB Output is correct
29 Correct 144 ms 17520 KB Output is correct
30 Correct 156 ms 17520 KB Output is correct
31 Correct 615 ms 18272 KB Output is correct
32 Correct 2100 ms 29016 KB Output is correct
33 Correct 730 ms 29016 KB Output is correct
34 Correct 1079 ms 29016 KB Output is correct
35 Correct 8 ms 29016 KB Output is correct
36 Correct 413 ms 29016 KB Output is correct
37 Execution timed out 3045 ms 40548 KB Time limit exceeded
38 Halted 0 ms 0 KB -