Submission #99389

# Submission time Handle Problem Language Result Execution time Memory
99389 2019-03-03T12:30:35 Z dantoh000 Park (BOI16_park) C++14
0 / 100
542 ms 49984 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
vector<iii> a;
int n,m,w,h;
vi p,rk;
int numedges = 0;
void init(int n){
    for (int i = 0; i < n; i++){
        p.push_back(i);
        rk.push_back(0);
    }
}
int findset(int x){
    return x == p[x] ? x : p[x] = findset(p[x]);
}
bool sameset(int x, int y){
    return findset(x) == findset(y);
}
void unionset(int i, int j){
    int x = findset(i);
    int y=  findset(j);
    if (x == y) return;
    numedges++;
    if (rk[x] < rk[y]){
        p[x] =y;
    }
    else{
        p[y] = x;
        if (rk[x] == rk[y]) rk[x]++;
    }
}
int sqrt(int x){
    return (int)(pow(x,0.50000000));
}
int dist(int i, int j){
    int r = a[i].first, x = a[i].second.first, y = a[i].second.second;
    if (j >= n){
        if (j == n) return x-r;
        if (j == n+1) return y-r;
        if (j == n+2) return w-x-r;
        if (j == n+3) return h-y-r;
    }
    else{
        int r1 = a[j].first, x1 = a[j].second.first, y1 = a[j].second.second;
        return sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)) - r1-r;
    }
}
int finder(int a, int b){
    if (a > b) swap(a,b);
    if (a == 0 && b == 1) return 0;
    if (a == 0 && b == 2) return 1;
    if (a == 0 && b == 3) return 2;
    if (a == 1 && b == 2) return 3;
    if (a == 1 && b == 3) return 4;
    if (a == 2 && b == 3) return 5;
}
main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("testdebug.txt","w",stdout);
    scanf("%lld%lld%lld%lld",&n,&m,&w,&h);
    for (int i = 0; i < n; i++){
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        a.push_back(iii(z,ii(x,y)));
    }
    vector<iii> edgelist;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n+4; j++){
            //printf("dist from %lld %lld = %lld\n",i,j,dist(i,j));
            edgelist.push_back(iii(dist(i,j),ii(i,j)));
        }
    }
    sort(edgelist.begin(),edgelist.end());
    init(n+4);
    bool b[6];
    b[0] = b[1] = b[2] = b[3] = b[4] = b[5] = true;
    int thres[6];
    for (auto cur : edgelist){
        int d = cur.first, x = cur.second.first, y = cur.second.second;
        //if (!sameset(x,y)) printf("%lld %lld %lld\n",d,x,y);
        unionset(x,y);
        if (b[0] && (sameset(n,n+1) || sameset(n+1,n+3) || sameset(n+1,n+2))){
            b[0] = false;
            thres[0] = d;
        }
        if (b[1] && (sameset(n,n+1) || sameset(n+1,n+3) || sameset(n+2,n+3) || sameset(n,n+2))){
            b[1] = false;
            thres[1] = d;
        }
        if (b[2] && (sameset(n,n+1) || sameset(n,n+2) || sameset(n,n+3))){
            b[2] = false;
            thres[2] = d;
        }
        if (b[3] && (sameset(n+2,n+1) || sameset(n+2,n) || sameset(n+2,n+3))){
            b[3] = false;
            thres[3] = d;
        }
        if (b[4] && (sameset(n+2,n+1) || sameset(n+1,n+3) || sameset(n,n+3) || sameset(n,n+2))){
            b[4] = false;
            thres[4] = d;
        }
        if (b[5] && (sameset(n+3,n) || sameset(n+3,n+1) || sameset(n+3,n+2))){
            b[5] = false;
            thres[5] = d;
        }
    }
    for (int i = 0; i < 6; i++){
        //printf("%lld ", thres[i]);
    }
    for (int i = 0; i < m; i++){
        int r,e;
        scanf("%lld%lld",&r,&e);
        r *= 2;
        e--;
        for (int i = 0; i < 4; i++){
            //printf("%lld %lld %lld\n",e,i,finder(e,i));
            if (e == i  || r < thres[finder(e,i)]){
                printf("%lld",i+1);
            }
        }
        printf("\n");
    }
}

Compilation message

park.cpp:61:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
park.cpp: In function 'long long int dist(long long int, long long int)':
park.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
park.cpp: In function 'long long int finder(long long int, long long int)':
park.cpp:60:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
park.cpp: In function 'int main()':
park.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld%lld%lld",&n,&m,&w,&h);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&x,&y,&z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:117:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&r,&e);
         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 494 ms 49756 KB Output is correct
2 Correct 480 ms 49884 KB Output is correct
3 Correct 478 ms 49884 KB Output is correct
4 Correct 477 ms 49756 KB Output is correct
5 Correct 485 ms 49832 KB Output is correct
6 Correct 512 ms 49904 KB Output is correct
7 Correct 542 ms 49816 KB Output is correct
8 Incorrect 508 ms 49984 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1424 KB Output is correct
2 Incorrect 60 ms 1296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 494 ms 49756 KB Output is correct
2 Correct 480 ms 49884 KB Output is correct
3 Correct 478 ms 49884 KB Output is correct
4 Correct 477 ms 49756 KB Output is correct
5 Correct 485 ms 49832 KB Output is correct
6 Correct 512 ms 49904 KB Output is correct
7 Correct 542 ms 49816 KB Output is correct
8 Incorrect 508 ms 49984 KB Output isn't correct
9 Halted 0 ms 0 KB -