Submission #1073584

#TimeUsernameProblemLanguageResultExecution timeMemory
1073584Jarif_RahmanPark (BOI16_park)C++17
100 / 100
464 ms73008 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; typedef long double ld; struct dsu{ int n; vector<int> p, sz; dsu(int _n): n(_n){ p.resize(n); sz.resize(n, 1); for(int i = 0; i < n; i++) p[i] = i; } int get(int x){ if(p[x] != x) p[x] = get(p[x]); return p[x]; } void unite(int a, int b){ a = get(a), b = get(b); if(a == b) return; if(sz[a] < sz[b]) swap(a, b); p[b] = a; sz[a]+=sz[b]; sz[b] = 0; } bool same(int a, int b){ return get(a) == get(b); } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; ld w, h; cin >> n >> m >> w >> h; vector<tuple<ld, ld, ld>> circles(n); vector<tuple<ld, int, int>> queries; for(auto &[x, y, r]: circles) cin >> x >> y >> r; for(int i = 0; i < m; i++){ ld r; int e; cin >> r >> e; queries.push_back({r, e, i}); } dsu ds(n+4); vector<tuple<ld, int, int>> op; for(int i = 0; i < n; i++){ auto [x1, y1, r1] = circles[i]; op.push_back({y1-r1, i, n}); op.push_back({w-x1-r1, i, n+1}); op.push_back({h-y1-r1, i, n+2}); op.push_back({x1-r1, i, n+3}); for(int j = i+1; j < n; j++){ auto [x2, y2, r2] = circles[j]; ld dis = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2); dis = sqrt(dis); op.push_back({dis-r1-r2, i, j}); } } sort(op.rbegin(), op.rend()); sort(queries.begin(), queries.end()); vector<pair<int, int>> sth[5][5]; sth[1][1] = {}; sth[1][2] = { {0,1}, {0,2}, {0,3} }; sth[1][3] = { {0,2}, {1,3}, {0,3}, {1,2} }; sth[1][4] = { {3,0}, {3,1}, {3,2} }; sth[2][1] = sth[1][2], sth[2][2] = {}; sth[2][3] = { {1,0}, {1,2}, {1,3} }; sth[2][4] = { {0,2}, {1,3}, {0,1}, {2,3} }; sth[3][1] = sth[1][3], sth[3][2] = sth[2][3], sth[3][3] = {}; sth[3][4] = { {2,0}, {2,1}, {2,3} }; sth[4][1] = sth[1][4], sth[4][2] = sth[2][4], sth[4][3] = sth[3][4], sth[4][4] = {}; vector<string> ans(m, ""); for(auto [r, e, in]: queries){ while(!op.empty() && get<0>(op.back()) < r*2.0){ auto [_, a, b] = op.back(); op.pop_back(); ds.unite(a, b); } for(int i = 1; i <= 4; i++){ bool ok = 1; for(auto [a, b]: sth[e][i]) ok&=!ds.same(n+a, n+b); if(ok) ans[in]+=('0'+i); } } for(auto x: ans) cout << x << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...