Submission #1052883

#TimeUsernameProblemLanguageResultExecution timeMemory
1052883caterpillowPark (BOI16_park)C++17
100 / 100
222 ms102044 KiB
#include <bits/stdc++.h> #include <ratio> 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; /* 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; }; struct Event { ll k; int t, f, s; bool operator<(const Event& rhs) const { return k == rhs.k ? t < rhs.t : k < rhs.k; } }; int n, q; ll w, h; vt<Event> evs; vt<int> ans; 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; ans.resize(q); trees.resize(n); F0R (i, n) { cin >> trees[i].x >> trees[i].y >> trees[i].r; } F0R (i, q) { ll r; int s; cin >> r >> s; evs.pb({2 * r, 1, s - 1, i}); } 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; evs.pb({dist + 1, 0, i, j}); } } F0R (i, n) { // right evs.pb({w - trees[i].x - trees[i].r + 1, 0, i, n}); // top evs.pb({h - trees[i].y - trees[i].r + 1, 0, i, n + 1}); // left evs.pb({trees[i].x - trees[i].r + 1, 0, i, n + 2}); // bot evs.pb({trees[i].y - trees[i].r + 1, 0, i, n + 3}); } sort(all(evs)); DSU dsu; dsu.init(n + 4); for (auto& ev : evs) { if (ev.t == 0) { dsu.unite(ev.f, ev.s); } else { int s = ev.f, qi = ev.s; int num = 0; 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) num = num * 10 + i + 1; } ans[qi] = num; } } for (int x : ans) cout << x << endl; }

Compilation message (stderr)

park.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...