답안 #1052874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052874 2024-08-11T05:19:27 Z caterpillow Park (BOI16_park) C++17
27 / 100
12 ms 564 KB
#include <bits/stdc++.h>

using namespace std;

using db = long double;
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

template<typename... Args> // tuples
ostream& operator<<(ostream& os, tuple<Args...> t) { 
    apply([&](Args... args) { string dlm = "{"; ((os << dlm << args, dlm = ", "), ...); }, t);
    return os << "}";
}

template<typename T, typename V> // pairs
ostream& operator<<(ostream& os, pair<T, V> p) { return os << "{" << p.f << ", " << p.s << "}"; }

template<class T, class = decltype(begin(declval<T>()))> // iterables
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& os, const T& v) {
    string dlm = "{";
    for (auto& i : v) os << dlm << i, dlm = ", ";
    return os << "}";  
}

template <typename T, typename... V>
void printer(string pfx, const char *names, T&& head, V&& ...tail) {
    int i = 0;
    while (names[i] && names[i] != ',') i++;
    constexpr bool is_str = is_same_v<decay_t<T>, const char*>;
    if (is_str) cerr << " " << head;
    else cerr << pfx, cerr.write(names, i) << " = " << head; 
    if constexpr (sizeof...(tail)) printer(is_str ? "" : ",", names + i + 1, tail...);
    else cerr << endl;
}

#ifdef LOCAL
#define dbg(...) printer(to_string(__LINE__) + ": ", #__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(x...)
#define cerr if (0) std::cerr
#endif

/*

answer queries in increasing radius of visitors
we can consider increasing the radius of visitors as expanding trees and pushing inwards the sides of the rectangle
this way, visitors are always points
for each pair of trees, there will be some radius such that the "gap" between them is filled

if we consider the walls and trees as nodes, if two opposing walls belong to the same connected component, then you cant go between them
we can do dsu and just spam stuff to check

*/

#define sq(x) ((x) * (x))

struct DSU {
    vt<int> e;
    void init(int n) {
        e.resize(n, -1);
    }
    int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (e[x] < e[y]) swap(x, y);
        e[y] += e[x];
        e[x] = y;
    }
    bool same_set(int u, int v) {
        return find(u) == find(v);
    }
};

ll floor_sqrt(ll x) {
    ll y = sqrt(x);
    while (y * y < x) y++;
    while (y * y > x) y--;
    return y;
}

struct Tree {
    ll x, y, r;
};

int n, q;
ll w, h; 
vt<Tree> trees;

// neighbour walls of each thingy
// walls are indexed starting from right, anticlockwise
vt<vt<int>> adj {
    {2, 3},
    {0, 3},
    {0, 1},
    {1, 2}
};

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> n >> q >> w >> h;
    trees.resize(n);

    F0R (i, n) {
        cin >> trees[i].x >> trees[i].y >> trees[i].r;
    }

    ll d, s; cin >> d >> s;
    s--;
    d *= 2;

    DSU dsu;
    dsu.init(n + 4);

    F0R (i, n) {
        FOR (j, i + 1, n) {
            ll dist = floor_sqrt(sq(trees[i].x - trees[j].x) + sq(trees[i].y - trees[j].y)) - trees[i].r - trees[j].r;
            if (dist < d) dsu.unite(i, j);
        }
    }
    F0R (i, n) {
        // right
        if (w - trees[i].x - trees[i].r + 1 < d) dsu.unite(i, n);
        // top
        if (h - trees[i].y - trees[i].r + 1 < d) dsu.unite(i, n + 1);
        // left
        if (trees[i].x - trees[i].r + 1 < d) dsu.unite(i, n + 2);
        // bot
        if (trees[i].y - trees[i].r + 1 < d) dsu.unite(i, n + 3);
    }

    F0R (i, 4) {
        bool good = true;

        if (s != i) {
            if ((i - s + 4) % 4 == 2) {
                // opposite
                for (int x : adj[(s + 1) % 4]) {
                    for (int y : adj[(i + 1) % 4]) {
                        good &= !dsu.same_set(n + x, n + y);
                    }
                }
            } else {
                // adjacent
                int com = -1; // common wall
                for (int x : adj[s]) for (int y : adj[i]) if (x == y) com = x; 

                F0R (j, 4) {
                    if (j != com) good &= !dsu.same_set(n + j, n + com);
                }
            }
        }

        if (good) cout << i + 1;
    }
    cout << endl;
}

Compilation message

park.cpp:112:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  112 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 8 ms 512 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 7 ms 564 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 7 ms 348 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 8 ms 512 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 12 ms 348 KB Output is correct
8 Correct 7 ms 564 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -