Submission #218675

# Submission time Handle Problem Language Result Execution time Memory
218675 2020-04-02T13:48:04 Z Ruxandra985 Park (BOI16_park) C++14
100 / 100
2224 ms 2296 KB
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
deque <int> dq;
struct idk{
    int x , y , r;
} c[DIMN];
int val[5][5];
int dist[DIMN];
int n , w , h;
double distt (idk x , idk y){
    return sqrt ( 1LL * (x.x - y.x) * (x.x - y.x) + 1LL * (x.y - y.y) * (x.y - y.y) );
}
void solve (int nod , int raza){
    int i;
    memset (dist , 0 , sizeof(dist));
    dq.push_back(nod);
    dist[nod] = 1;
    while (!dq.empty()){
        nod = dq.front();
        dq.pop_front();

        for (i = 1 ; i <= n ; i++){
            if (dist[i])
                continue;
            if (nod <= n && distt(c[nod] , c[i]) < c[i].r + c[nod].r + 2 * raza){
                dist[i] = 1;
                dq.push_back(i);
            }
            else if (nod == n + 1 && c[i].y < c[i].r + 2 * raza) {
                dist[i] = 1;
                dq.push_back(i);
            }
            else if (nod == n + 2 && (w - c[i].x) < c[i].r + 2 * raza){
                dist[i] = 1;
                dq.push_back(i);
            }
            else if (nod == n + 3 && (h - c[i].y) < c[i].r + 2 * raza){
                dist[i] = 1;
                dq.push_back(i);
            }
            else if (nod == n + 4 && c[i].x < c[i].r + 2 * raza){
                dist[i] = 1;
                dq.push_back(i);
            }

        }

        if (nod <= n){
            i = nod;
            if (c[i].y < c[i].r + 2 * raza) {
                dist[n + 1] = 1;
            }
            if ((w - c[i].x) < c[i].r + 2 * raza){
                dist[n + 2] = 1;
            }
            if ((h - c[i].y) < c[i].r + 2 * raza){
                dist[n + 3] = 1;
            }
            if (c[i].x < c[i].r + 2 * raza){
                dist[n + 4] = 1;
            }


        }


    }

}


int connect (int i , int j , int raza){

    /// cu raza, liniile i si j se conecteaza?
    //if (i == 1 && j == 2)
      //  printf ("a");
    solve(n + i , raza);

    return dist[n + j];

}
int main()
{
    FILE *fin = stdin;
    FILE *fout = stdout;
    int i , m , j , st , dr , mid , en , r;
    fscanf (fin,"%d%d%d%d",&n,&m,&w,&h);
    /// w e pe ox , h e pe oy
    for (i = 1 ; i <= n ; i++){
        fscanf (fin,"%d%d%d",&c[i].x,&c[i].y,&c[i].r);
    }

    /// la ce raza incep sa fie conectate laturile intre ele??

    for (i = 1 ; i < 4 ; i++){
        for (j = i + 1 ; j <= 4 ; j++){
            st = 0;
            dr = 1000000000;
            while (st <= dr){
                mid = (st + dr)/2;
                if (connect (i , j , mid))
                    dr = mid - 1;
                else st = mid + 1;
            }

            val[i][j] = st; /// st e prima raza asa incat laturile i si j sunt conectate
        }
    }


    for (i = 1 ; i <= m ; i++){
        fscanf (fin,"%d%d",&r,&en);

        if (en == 1){

            fprintf (fout,"1");

            if (val[1][4] <= r){
                fprintf (fout,"\n");
                continue;
            }

            if (min(val[1][2] , val[1][3]) > r)
                fprintf (fout,"2");
            if (min(val[2][4] , min(val[1][3] , val[2][3])) > r)
                fprintf (fout,"3");
            if (min(val[2][4] , val[3][4]) > r)
                fprintf (fout,"4");


        }
        else if (en == 2){

            if (val[1][2] <= r){
                fprintf (fout,"2\n");
                continue;
            }

            if (min(val[1][4] , val[1][3]) > r)
                fprintf (fout,"1");

            fprintf (fout,"2");

            if (min(val[2][4] , val[2][3]) > r)
                fprintf (fout,"3");
            if (min(val[1][3] , min(val[2][4] , val[3][4])) > r)
                fprintf (fout,"4");

        }
        else if (en == 3){

            if (val[2][3] <= r){
                fprintf (fout,"3\n");
                continue;
            }

            if (min(val[2][4] , min(val[1][4] , val[1][3])) > r)
                fprintf (fout,"1");

            if (min(val[1][2] , val[2][4]) > r)
                fprintf (fout,"2");

            fprintf (fout,"3");

            if (min(val[1][3] , val[3][4]) > r)
                fprintf (fout,"4");

        }
        else if (en == 4){

            if (val[3][4] <= r){
                fprintf (fout,"4\n");
                continue;
            }

            if (min(val[1][4] , val[2][4]) > r)
                fprintf (fout,"1");

            if (min(val[2][4] , min(val[1][2] , val[1][3])) > r)
                fprintf (fout,"2");

            if (min(val[1][3] , val[2][3]) > r)
                fprintf (fout,"3");

            fprintf (fout,"4");

        }

        fprintf (fout,"\n");

    }

    return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:88:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d%d%d",&n,&m,&w,&h);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:91:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d%d",&c[i].x,&c[i].y,&c[i].r);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:113:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&r,&en);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1659 ms 788 KB Output is correct
2 Correct 2224 ms 888 KB Output is correct
3 Correct 1726 ms 888 KB Output is correct
4 Correct 2124 ms 888 KB Output is correct
5 Correct 2009 ms 844 KB Output is correct
6 Correct 1837 ms 760 KB Output is correct
7 Correct 1543 ms 888 KB Output is correct
8 Correct 1246 ms 888 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 1144 KB Output is correct
2 Correct 77 ms 2296 KB Output is correct
3 Correct 64 ms 2040 KB Output is correct
4 Correct 61 ms 2168 KB Output is correct
5 Correct 65 ms 2168 KB Output is correct
6 Correct 64 ms 2168 KB Output is correct
7 Correct 47 ms 2168 KB Output is correct
8 Correct 46 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1659 ms 788 KB Output is correct
2 Correct 2224 ms 888 KB Output is correct
3 Correct 1726 ms 888 KB Output is correct
4 Correct 2124 ms 888 KB Output is correct
5 Correct 2009 ms 844 KB Output is correct
6 Correct 1837 ms 760 KB Output is correct
7 Correct 1543 ms 888 KB Output is correct
8 Correct 1246 ms 888 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 7 ms 768 KB Output is correct
11 Correct 67 ms 1144 KB Output is correct
12 Correct 77 ms 2296 KB Output is correct
13 Correct 64 ms 2040 KB Output is correct
14 Correct 61 ms 2168 KB Output is correct
15 Correct 65 ms 2168 KB Output is correct
16 Correct 64 ms 2168 KB Output is correct
17 Correct 47 ms 2168 KB Output is correct
18 Correct 46 ms 2168 KB Output is correct
19 Correct 2119 ms 2180 KB Output is correct
20 Correct 1762 ms 2296 KB Output is correct
21 Correct 1813 ms 2272 KB Output is correct
22 Correct 2107 ms 2044 KB Output is correct
23 Correct 1969 ms 2168 KB Output is correct
24 Correct 1518 ms 2180 KB Output is correct