Submission #99548

# Submission time Handle Problem Language Result Execution time Memory
99548 2019-03-05T02:45:49 Z ShaneOng Park (BOI16_park) C++14
100 / 100
684 ms 132948 KB
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long double ld;
typedef pair<ld,ii> ldii;
int n,m,h,w,ans[100009][4],X[2009],Y[2009],rad[2009];
vector<ldii> edgeL;
vector<int> p,rnk;
int findS(int a){
    return a==p[a]?a:(p[a]=findS(p[a]));
}
void unionS(int a,int b){
    a=findS(a),b=findS(b);
    if(a!=b){
        if(rnk[a]<rnk[b])
            p[a]=b;
        else{
            p[b]=a;
            if(rnk[a]==rnk[b])
                rnk[a]++;
        }
    }
}
int main(){
    scanf("%d%d%d%d",&n,&m,&w,&h);
    for(int x=0;x<n;x++){
        p.push_back(x);
        rnk.push_back(0);
        scanf("%d%d%d",&X[x],&Y[x],&rad[x]);
    }
    for(int x=0;x<4;x++){
        p.push_back(n+x);
        rnk.push_back(0);
    }
    for(int x=0;x<n;x++){
        for(int y=0;y<x;y++){
            ld temp = sqrt((ld)(X[x]-X[y])*(X[x]-X[y])+(ld)(Y[x]-Y[y])*(Y[x]-Y[y]))-rad[x]-rad[y];
            edgeL.push_back(ldii(temp,ii(x,y)));
        }
    }
    for(int x=0;x<n;x++){
        edgeL.push_back(ldii((ld)h-Y[x]-rad[x],ii(x,n+3)));
        edgeL.push_back(ldii((ld)Y[x]-rad[x],ii(x,n+1)));
        edgeL.push_back(ldii((ld)w-X[x]-rad[x],ii(x,n+2)));
        edgeL.push_back(ldii((ld)X[x]-rad[x],ii(x,n)));
    }
    for(int x=0,a,b;x<m;x++){
        scanf("%d%d",&a,&b);
        edgeL.push_back(ldii((ld)2.0*a,ii(-x-1,b)));
    }
    sort(edgeL.begin(),edgeL.end());
    for(ldii edge: edgeL){
        int b=edge.second.first,a=edge.second.second;
        //printf("%Lf, %d %d\n",edge.first,a,b);
        if(b>=0){
            if(findS(a)!=findS(b)){
                unionS(a,b);
            }
        }else{
            ans[-b-1][a-1]=1;
            if(findS(n+a-1)!=findS(n+(a)%4)){
                if(findS(n+(a)%4)!=findS(n+(a+2)%4)){
                    if(findS(n+(a)%4)!=findS(n+(a+1)%4))
                        ans[-b-1][a%4]=1;

                }
                if(findS(n+a-1)!=findS(n+(a+1)%4)){
                    if(findS(n+(a)%4)!=findS(n+(a+2)%4))
                        if(findS(n+(a+2)%4)!=findS(n+(a+1)%4))
                            ans[-b-1][(a+1)%4]=1;
                    if(findS(n+(a+3)%4)!=findS(n+(a+2)%4))
                        ans[-b-1][(a+2)%4]=1;
                }
            }

        }
    }
    for(int x=0;x<m;x++){
        for(int y=0;y<4;y++){
            if(ans[x][y]==1)
                printf("%d",y+1);
        }
        printf("\n");
    }
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d",&n,&m,&w,&h);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&X[x],&Y[x],&rad[x]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 597 ms 66200 KB Output is correct
2 Correct 528 ms 66200 KB Output is correct
3 Correct 515 ms 66196 KB Output is correct
4 Correct 546 ms 66192 KB Output is correct
5 Correct 543 ms 66200 KB Output is correct
6 Correct 507 ms 66200 KB Output is correct
7 Correct 517 ms 66200 KB Output is correct
8 Correct 514 ms 66200 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 6236 KB Output is correct
2 Correct 81 ms 7132 KB Output is correct
3 Correct 104 ms 7232 KB Output is correct
4 Correct 78 ms 7136 KB Output is correct
5 Correct 86 ms 7296 KB Output is correct
6 Correct 91 ms 7260 KB Output is correct
7 Correct 70 ms 6644 KB Output is correct
8 Correct 66 ms 6544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 597 ms 66200 KB Output is correct
2 Correct 528 ms 66200 KB Output is correct
3 Correct 515 ms 66196 KB Output is correct
4 Correct 546 ms 66192 KB Output is correct
5 Correct 543 ms 66200 KB Output is correct
6 Correct 507 ms 66200 KB Output is correct
7 Correct 517 ms 66200 KB Output is correct
8 Correct 514 ms 66200 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 90 ms 6236 KB Output is correct
12 Correct 81 ms 7132 KB Output is correct
13 Correct 104 ms 7232 KB Output is correct
14 Correct 78 ms 7136 KB Output is correct
15 Correct 86 ms 7296 KB Output is correct
16 Correct 91 ms 7260 KB Output is correct
17 Correct 70 ms 6644 KB Output is correct
18 Correct 66 ms 6544 KB Output is correct
19 Correct 643 ms 132884 KB Output is correct
20 Correct 627 ms 132840 KB Output is correct
21 Correct 676 ms 132948 KB Output is correct
22 Correct 684 ms 132820 KB Output is correct
23 Correct 664 ms 132820 KB Output is correct
24 Correct 668 ms 132948 KB Output is correct