답안 #1096358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096358 2024-10-04T10:52:31 Z anhthi Park (BOI16_park) C++14
0 / 100
221 ms 65436 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }

template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }

template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }

int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}

const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 123456789;

const int N = 5e5 + 5, BASE = 307;

void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

ll n, q, w, h;
struct Edge {
    ll u, v, d;
    bool operator < (const Edge &e) const {
        return d < e.d;
    }
};
struct Query {
    ll r, e, i;
    void input(int id) {
        i = id;
        cin >> r >> e;
        r *= 2;
    }
    bool operator < (const Query &q) const {
        return r < q.r;
    }
} query[N];

vector<Edge> edges;
array<ll, 3> points[N];

ll sqr(ll x) {
    return 1LL * x * x;
}
ll dist(array<ll, 3> x, array<ll, 3> y) {
    return sqrt(sqr(x[0] - y[0]) + sqr(x[1] - y[1])) - x[2] - y[2];
}

struct dsu {
    vector<ll> par, sz;
    dsu(ll n) {
        par.resize(n + 5);
        sz.resize(n + 5, 1);
        rep(i, n) par[i] = i;
    }
    ll root(ll u) {
        return u == par[u] ? u : par[u] = root(par[u]);
    }
    void unite(ll u, ll v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (sz[u] < sz[v])
            swap(u, v);
        par[v] = u;
        sz[u] += sz[v];
        return;
    }
    bool connect(ll u, ll v) {
        return root(u) == root(v);
    }
};

string res[N];

signed main(void) {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> q >> w >> h;
    forn(i, 1, n) {
        ll x, y, r;
        cin >> x >> y >> r;
        points[i] = {x, y, r};
        edges.pb({n + 1, i, x - r});
        edges.pb({n + 2, i, y - r});
        edges.pb({n + 3, i, w - x - r});
        edges.pb({n + 4, i, h - y - r});
    }
    forn(i, 1, n) forn(j, i + 1, n) {
        edges.pb({i, j, dist(points[i], points[j])});
    }
    sort(all(edges));
    rep(i, q) query[i].input(i);
    sort(query + 1, query + 1 + q);

    ll eID = 0;
    dsu d(n + 5);
    forn(i, 1, q) {
        while (eID < sz(edges) && edges[eID].d < query[i].r) {
            d.unite(edges[eID].u, edges[eID].v);
            eID++;
        }
        string ans;
        if (query[i].e == 1) {
            ans = "1";
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 2, n + 4) && !d.connect(n + 4, n + 3))
                ans += '2';
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 1, n + 3) && !d.connect(n + 1, n + 2))
                ans += '4';
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 2, n + 3) && !d.connect(n + 1, n + 3) && !d.connect(n + 2, n + 4))
                ans += '3';
        }
        else if (query[i].e == 2) {
            ans = "2";
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 2, n + 4) && !d.connect(n + 4, n + 3))
                ans += '1';
            if (!d.connect(n + 3, n + 4) && !d.connect(n + 2, n + 3) && !d.connect(n + 1, n + 3))
                ans += '3';
            if (!d.connect(n + 1, n + 3) && !d.connect(n + 2, n + 4) && !d.connect(n + 1, n + 2) && !d.connect(n + 3, n + 4))
                ans += '4';
        }
        else if (query[i].e == 3) {
            ans = "3";
            if (!d.connect(n + 2, n + 3) && !d.connect(n + 4, n + 3) && !d.connect(n + 1, n + 3))
                ans += '2';
            if (!d.connect(n + 2, n + 3) && !d.connect(n + 1, n + 2) && !d.connect(n + 4, n + 2))
                ans += '4';
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 2, n + 3) && !d.connect(n + 1, n + 3) && !d.connect(n + 2, n + 4))
                ans += '1';
        }
        else {
            ans = "4";
            if (!d.connect(n + 1, n + 4) && !d.connect(n + 1, n + 3) && !d.connect(n + 1, n + 2))
                ans += '1';
            if (!d.connect(n + 1, n + 3) && !d.connect(n + 2, n + 4) && !d.connect(n + 1, n + 2) && !d.connect(n + 3, n + 4))
                ans += '2';
            if (!d.connect(n + 2, n + 3) && !d.connect(n + 1, n + 2) && !d.connect(n + 4, n + 2))
                ans += '3';
        }
        res[query[i].i] = ans;
    }

    rep(i, q) cout << res[i] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 65436 KB Output is correct
2 Incorrect 221 ms 65400 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 20428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 65436 KB Output is correct
2 Incorrect 221 ms 65400 KB Output isn't correct
3 Halted 0 ms 0 KB -