Submission #1352466

#TimeUsernameProblemLanguageResultExecution timeMemory
1352466vjudge1Park (BOI16_park)C++17
0 / 100
2073 ms880 KiB
#include <bits/stdc++.h>
using namespace std;

struct DSU {
    vector<int> p;
    DSU(int n) : p(n) { iota(begin(p), end(p), 0); }
    int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
    void unite(int a, int b) {
        a = find(a);
        b = find(b);
        if(a != b) p[a] = b;
    }
};

int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);

    int n, m, W, H;
    cin >> n >> m >> W >> H;
    vector<int> x(n), y(n), r(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i];

    while(m--) {
        int R, start;
        cin >> R >> start;

        DSU dsu(n + 4);
        int LEFT = n, RIGHT = n + 1, BOTTOM = n + 2, TOP = n + 3;
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                long long dx = x[i] - x[j];
                long long dy = y[i] - y[j];
                long long dist2 = dx*dx + dy*dy;
                long long rad = r[i] + r[j] + 2LL * R;
                if(dist2 <= rad * rad) dsu.unite(i, j);
            }
        }

        for(int i = 0; i < n; i++) {
            if(x[i] - r[i] - R <= 0) dsu.unite(i, LEFT);
            if(x[i] + r[i] + R >= W) dsu.unite(i, RIGHT);
            if(y[i] - r[i] - R <= 0) dsu.unite(i, BOTTOM);
            if(y[i] + r[i] + R >= H) dsu.unite(i, TOP);
        }

        bool can[5][5];
        memset(can, true, sizeof(can));
        if(dsu.find(LEFT) == dsu.find(RIGHT)) for(int a : {1,2}) for(int b : {3,4}) can[a][b] = can[b][a] = false;
        if(dsu.find(BOTTOM) == dsu.find(TOP)) for(int a : {1,4}) for(int b : {2,3}) can[a][b] = can[b][a] = false;

        if(dsu.find(LEFT) == dsu.find(BOTTOM)) for(int i = 1; i <= 4; i++) can[1][i] = can[i][1] = false;
        if(dsu.find(RIGHT) == dsu.find(BOTTOM)) for(int i = 1; i <= 4; i++) can[2][i] = can[i][2] = false;
        if(dsu.find(RIGHT) == dsu.find(TOP)) for(int i = 1; i <= 4; i++) can[3][i] = can[i][3] = false;
        if(dsu.find(LEFT) == dsu.find(TOP)) for(int i = 1; i <= 4; i++) can[4][i] = can[i][4] = false;

        for(int i = 1; i <= 4; i++) if(can[start][i] || i == start) cout << i;
        cout << '\n';
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...