Submission #720988

# Submission time Handle Problem Language Result Execution time Memory
720988 2023-04-10T02:05:03 Z Username4132 Circle selection (APIO18_circle_selection) C++14
0 / 100
3000 ms 209484 KB
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define forn(i, n) for(int i=0; i<n; ++i)
#define F first
#define S second
#define PB push_back

struct circle{
    pii c;
    int r, ind;
};

struct quad{
    pii a[4];
    quad(pii A, pii B, pii C, pii D){a[0]=A, a[1]=B, a[2]=C, a[3]=D;}
};

pii reduce(pii a, int ind){
    return {(a.F>>ind), (a.S>>ind)};
}

quad cover(pii c, int r, int i){
    pii lelo={c.F-r, c.S-r}, lehi={c.F-r, c.S+r}, rilo={c.F+r, c.S-r}, rihi={c.F+r, c.S+r};
    return quad(reduce(lelo, i), reduce(lehi, i), reduce(rilo, i), reduce(rihi, i));
}

bool inters(circle a, circle b){
    ll dx=b.c.F-a.c.F, dy=b.c.S-a.c.S, sum=a.r+b.r;
    return (dx*dx + dy*dy <= sum*sum);
}

const int MAXN=300010;
int n, ans[MAXN];
circle arr[MAXN];
map<pii, vector<int>> mp[36];

int main(){
    scanf("%d", &n);
    forn(i, n){
        scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
        arr[i].c.F+=1000000010, arr[i].c.S+=1000000010;
        arr[i].ind=i;
    }
    sort(arr, arr+n, [](circle a, circle b){
        return a.r!=b.r? a.r>b.r : a.ind<b.ind;
    });
    
    
    forn(i, n){
        int mn=i;
        forn(j, 32) if((1LL<<j)>(2*arr[i].r)){
            quad cov = cover(arr[i].c, arr[i].r, j);
            forn(k, 4) for(int ind:mp[j][cov.a[k]]) if(inters(arr[i], arr[ind])) mn=min(mn, ind);
        }
        ans[arr[i].ind]=arr[mn].ind;
        if(mn==i){
            int ex = 8*sizeof(int)-__builtin_clz(arr[i].r)+1;
            quad q = cover(arr[i].c, arr[i].r, ex);
            forn(j, 4) mp[ex][q.a[j]].PB(i);
        }
    }
    forn(i, n) printf("%d ", ans[i]+1);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:45:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   45 |         scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
      |                ~^
      |                 |
      |                 int*
      |                %lld
circle_selection.cpp:45:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   45 |         scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
      |                   ~^
      |                    |
      |                    int*
      |                   %lld
circle_selection.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
circle_selection.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Incorrect 3 ms 7252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 188 ms 10780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 1108 ms 82404 KB Output is correct
3 Execution timed out 3076 ms 209060 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 209484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Incorrect 3 ms 7252 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7252 KB Output is correct
2 Correct 3 ms 7252 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 3 ms 7252 KB Output is correct
5 Correct 3 ms 7252 KB Output is correct
6 Correct 3 ms 7252 KB Output is correct
7 Correct 3 ms 7252 KB Output is correct
8 Incorrect 3 ms 7252 KB Output isn't correct
9 Halted 0 ms 0 KB -