Submission #771729

# Submission time Handle Problem Language Result Execution time Memory
771729 2023-07-03T08:28:28 Z gagik_2007 Circle selection (APIO18_circle_selection) C++17
7 / 100
352 ms 20336 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

class Circle {
public:
    ll x,y;
    ll r;
    int ind;
    Circle(ll xx, ll yy, ll rr, int i){
        x=xx;
        y=yy;
        r=rr;
        ind=i;
    }
    bool operator<(const Circle& other) const{
        if(r==other.r)return ind>other.ind;
        return r<other.r;
    }
};

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3e5+7;
ll n,m,k;
vector<Circle>d;
bool jnj[N];

bool isHatel(const Circle& a, const Circle& b){
    ll xt=a.x-b.x;
    ll yt=a.y-b.y;
    ll rt=a.r+b.r;
    return xt*xt+yt*yt<=rt*rt;
}

bool compRight(const Circle& a, const Circle& b){
    return a.x+a.r<b.x+b.r;
}

bool compLeft(const Circle& a, const Circle& b){
    return a.x-a.r<b.x-b.r;
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++){
        int x,y,r;
        cin>>x>>y>>r;
        d.push_back(Circle(x,y,r,i));
    }
    vector<int>ans(n);
    if(n<=5000){
        sort(d.begin(),d.end());
        reverse(d.begin(),d.end());
        for(int i=0;i<n;i++){
            // cout<<d[i].ind<<" ";
            if(!jnj[d[i].ind]){
                ans[d[i].ind]=d[i].ind;
                jnj[d[i].ind]=true;
                for(int j=0;j<n;j++){
                    if(!jnj[d[j].ind]&&isHatel(d[i],d[j])){
                        ans[d[j].ind]=d[i].ind;
                        jnj[d[j].ind]=true;
                    }
                }
            }
        }
        for(int x:ans)cout<<1+x<<" ";
        cout<<endl;
        return 0;
    }
    sort(d.begin(),d.end(),compLeft);
    vector<int>pl;
    vector<int>rpl(n);
    for(int i=0;i<n;i++){
        pl.push_back(d[i].ind);
        rpl[d[i].ind]=i;
    }
    sort(d.begin(),d.end(),compRight);
    vector<int>pr;
    vector<int>rpr(n);
    for(int i=0;i<n;i++){
        pr.push_back(d[i].ind);
        rpr[d[i].ind]=i;
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    for(int i=0;i<n;i++){
        if(!jnj[d[i].ind]){
            ans[d[i].ind]=d[i].ind;
            jnj[d[i].ind]=true;
            int ind=rpl[d[i].ind];
            int l=ind-1;
            while(l>=0&&isHatel(d[pl[l]],d[i])){
                ans[d[pl[l]].ind]=d[i].ind;
                jnj[d[pl[l]].ind]=true;
                l--;
            }
            int r=ind+1;
            while(r<n&&isHatel(d[pl[r]],d[i])){
                ans[d[pl[r]].ind]=d[i].ind;
                jnj[d[pl[r]].ind]=true;
                r++;
            }
            ind=rpr[d[i].ind];
            l=ind-1;
            while(l>=0&&isHatel(d[pr[l]],d[i])){
                ans[d[pr[l]].ind]=d[i].ind;
                jnj[d[pr[l]].ind]=true;
                l--;
            }
            r=ind+1;
            while(r<n&&isHatel(d[pr[r]],d[i])){
                ans[d[pr[r]].ind]=d[i].ind;
                jnj[d[pr[r]].ind]=true;
                r++;
            }
        }
    }
    for(int x:ans)cout<<1+x<<" ";
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 31 ms 608 KB Output is correct
23 Correct 37 ms 724 KB Output is correct
24 Correct 39 ms 596 KB Output is correct
25 Correct 30 ms 596 KB Output is correct
26 Correct 30 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 332 ms 20336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 117 ms 6580 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 352 ms 20216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 31 ms 608 KB Output is correct
23 Correct 37 ms 724 KB Output is correct
24 Correct 39 ms 596 KB Output is correct
25 Correct 30 ms 596 KB Output is correct
26 Correct 30 ms 596 KB Output is correct
27 Incorrect 13 ms 920 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 5 ms 596 KB Output is correct
20 Correct 5 ms 596 KB Output is correct
21 Correct 7 ms 596 KB Output is correct
22 Correct 31 ms 608 KB Output is correct
23 Correct 37 ms 724 KB Output is correct
24 Correct 39 ms 596 KB Output is correct
25 Correct 30 ms 596 KB Output is correct
26 Correct 30 ms 596 KB Output is correct
27 Incorrect 332 ms 20336 KB Output isn't correct
28 Halted 0 ms 0 KB -