Submission #99386

# Submission time Handle Problem Language Result Execution time Memory
99386 2019-03-03T11:49:47 Z dantoh000 Park (BOI16_park) C++14
0 / 100
1040 ms 49956 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;
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;
    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((long double)x+0.5,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;
    }
}
main(){
    //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;
    vector<iii> qu;
    for (int i = 0; i < m; i++){
        int x,y;
        scanf("%lld%lld",&x,&y);
        qu.push_back(iii(x*2,ii(y-1,i)));
    }
    sort(qu.begin(),qu.end());
    string ans[m];
    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);
    int ce, cv;
    bool b[4];
    b[0] = b[1] = b[2] = b[3] = true;
    ce = cv = 0;
    while (cv < m){
        iii v = qu[cv];
        int r = v.first, e = v.second.first, id = v.second.second;
        //printf("at %lld %lld %lld\n",r,e,id);
        while (ce < edgelist.size() && edgelist[ce].first < r){
            //printf("unioning set %lld %lld %lld\n",edgelist[ce].first, edgelist[ce].second.first, edgelist[ce].second.second);
            unionset(edgelist[ce].second.first, edgelist[ce].second.second);
            ce++;
        }
        for (int i = 0; i < 4; i++){
            b[i] &= !sameset(n+i,n+(i+1)%4);
            //printf("at size %lld, b[%lld] = %d\n",r,i,b[i]);
        }
        ans[id] = "";
        for (int i = 0; i < 4; i++){
            if (e == i || (b[e] && b[i])) ans[id] += (char)(i)+'1';
        }
        ans[id] += '\n';
        cv++;
    }
    for (int i = 0; i < m; i++){
        cout << ans[i];
    }
}

Compilation message

park.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
park.cpp: In function 'int main()':
park.cpp:83:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (ce < edgelist.size() && edgelist[ce].first < r){
                ~~~^~~~~~~~~~~~~~~~~
park.cpp: In function 'long long int dist(long long int, long long int)':
park.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
park.cpp: In function 'int main()':
park.cpp:52: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:55: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:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1004 ms 49816 KB Output is correct
2 Correct 996 ms 49900 KB Output is correct
3 Correct 1040 ms 49956 KB Output is correct
4 Correct 980 ms 49924 KB Output is correct
5 Correct 1016 ms 49872 KB Output is correct
6 Correct 993 ms 49796 KB Output is correct
7 Incorrect 992 ms 49756 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 7468 KB Output is correct
2 Correct 66 ms 7400 KB Output is correct
3 Incorrect 64 ms 7528 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1004 ms 49816 KB Output is correct
2 Correct 996 ms 49900 KB Output is correct
3 Correct 1040 ms 49956 KB Output is correct
4 Correct 980 ms 49924 KB Output is correct
5 Correct 1016 ms 49872 KB Output is correct
6 Correct 993 ms 49796 KB Output is correct
7 Incorrect 992 ms 49756 KB Output isn't correct
8 Halted 0 ms 0 KB -