답안 #51064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51064 2018-06-16T02:15:03 Z edisonhello 원 고르기 (APIO18_circle_selection) C++11
0 / 100
2641 ms 42080 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 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);
        }
    };

    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();
        }
        pair<int,int> pos(c[masterPtr].x/D,c[masterPtr].y/D);
        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;
                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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Incorrect 8 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 16800 KB Output is correct
2 Incorrect 252 ms 17140 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 17140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2641 ms 42080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Incorrect 8 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Incorrect 8 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -