Submission #860358

# Submission time Handle Problem Language Result Execution time Memory
860358 2023-10-12T17:47:43 Z TahirAliyev Park (BOI16_park) C++17
0 / 100
495 ms 70588 KB
#include <bits/stdc++.h>

#define ll long long
#define int ll
#define pii pair<int, int>
#define double long double


using namespace std;

const int MAX1 = 2020, MAX2 = 1e5 + 5;

struct tree{
    double r; 
    int x, y;
};

struct edge{
    double r;
    int x, y;
};

int n, m, w, h;

tree trees[MAX1];

vector<edge> E;
vector<array<int, 3>> Q;

double dist(int x1, int y1, int x2, int y2){
    return sqrt(1ll * (x1 - x2) * (x1 - x2) + 1ll * (y1 - y2) * (y1 - y2));
}

int par[MAX1];
string ans[MAX2];

int get(int u){
    if(par[u] < 0) return u;
    return par[u] = get(par[u]);
}

bool con(int u, int v){
    return get(u) == get(v);
}

void unite(int u, int v){
    u = get(u);
    v = get(v);
    if(u == v) return;
    if(-par[u] < -par[v]){
        swap(u, v);
    }
    par[u] += par[v];
    par[v] = u;
}

bool comp(edge a, edge b){
    return a.r < b.r;
}

signed main(){
    memset(par, -1, sizeof(par));
    cin >> n >> m >> w >> h;
    for(int i = 1; i <= n; i++){
        int x, y, r; cin >> x >> y >> r;
        trees[i] = {1.0 * r, x, y};
    }
    for(int i = 1; i <= n; i++){
        E.push_back({1.0 * trees[i].x - trees[i].r, i, n + 1});
        E.push_back({1.0 * h - trees[i].y - trees[i].r, i, n + 2});
        E.push_back({1.0 * w - trees[i].x - trees[i].r, i, n + 3});
        E.push_back({1.0 * trees[i].y - trees[i].r, i, n + 4});
    }  
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            double d = dist(trees[i].x, trees[i].y, trees[j].x, trees[j].y);
            E.push_back({d - trees[i].r - trees[j].r, i, j});
        }
    }
    sort(E.begin(), E.end(), comp);
    for(int i = 1; i <= m; i++){
        int r, e; cin >> r >> e;
        Q.push_back({r, e, i});
    }
    sort(Q.begin(), Q.end());
    int id = 0;
    for(auto q : Q){
        while(id < E.size() && E[id].r < 2.0 * q[0]){
            unite(E[id].x, E[id].y);
            id++;
        }
        
        bool isB[5];
        isB[1] = con(n + 1, n + 2);
        isB[2] = con(n + 2, n + 3);
        isB[3] = con(n + 3, n + 4);
        isB[4] = con(n + 4, n + 1);
        bool hor = con(n + 1, n + 3);
        bool ver = con(n + 2, n + 4);
        if(isB[q[1]]){
            ans[q[2]] = '0' + q[1];
            continue;
        }
        string s = "";
        if(q[1] == 1){
            s += '1';
            if(!isB[2] || !ver) s += '2';
            if(!isB[3] || !ver || !hor) s += '3';
            if(!isB[4] || !hor) s += '4';
        }
        if(q[1] == 2){
            if(!isB[1] || !ver) s += '1';
            s += '2';
            if(!isB[3] || !hor) s += '3';
            if(!isB[4] || !ver || !hor) s += '4';
        }
        if(q[1] == 3){
            if(!isB[1] || !ver || !hor) s += '1';
            if(!isB[2] || !hor) s += '2';
            s += '3';
            if(!isB[4] || !ver) s += '4';
        }
        if(q[1] == 4){
            if(!isB[1] || !hor) s += '1';
            if(!isB[2] || !ver && !hor) s += '2';
            if(!isB[3] || !ver) s += '3';
            s += '4';
        }
        ans[q[2]] = s;
    }
    for(int i = 1; i <= m; i++){
        cout << ans[i] << '\n';
    }
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:88:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         while(id < E.size() && E[id].r < 2.0 * q[0]){
      |               ~~~^~~~~~~~~~
park.cpp:125:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  125 |             if(!isB[2] || !ver && !hor) s += '2';
      |                           ~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 495 ms 70076 KB Output is correct
2 Incorrect 494 ms 70588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 7868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 495 ms 70076 KB Output is correct
2 Incorrect 494 ms 70588 KB Output isn't correct
3 Halted 0 ms 0 KB -