Submission #638066

#TimeUsernameProblemLanguageResultExecution timeMemory
638066KarliverPark (BOI16_park)C++17
100 / 100
304 ms37636 KiB
#include <bits/stdc++.h> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i) #define sz(x) (int)x.size() #define ff first #define se second #define mp make_pair using ll = long long; int MOD = 998244353; const int INF = 1e9 + 1; const int N = 2e5 + 10; const double eps = 1e-7; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template<class T, size_t SZ> using AR = array<T, SZ>; template<class T> using PR = pair<T, T>; template <typename XPAX> bool ckma(XPAX &x, XPAX y) { return (x < y ? x = y, 1 : 0); } template <typename XPAX> bool ckmi(XPAX &x, XPAX y) { return (x > y ? x = y, 1 : 0); } void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) int n, m, w, h; double dist(int x1, int y1, int x2, int y2) { long long dx = x1-x2, dy = y1-y2; return double(sqrt(dx * dx + dy * dy)); } struct DSU { vector<int> e; DSU(int N) { e = vector<int>(N, -1); } // get representive component (uses path compression) int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } bool same_set(int a, int b) { return get(a) == get(b); } int size(int x) { return -e[get(x)]; } bool unite(int x, int y) { // union by size x = get(x), y = get(y); if (x == y) return false; if (e[x] > e[y]) swap(x, y); e[x] += e[y]; e[y] = x; return true; } }; void solve() { cin >> n >> m >> w >> h; vector<int> x(n), y(n); V<double> r(n); forn(i, n) cin >> y[i] >> x[i] >> r[i]; vector<array<int, 3>> Q(m); forn(i, m) { cin >> Q[i][0] >> Q[i][1]; Q[i][1]--; Q[i][2] = i; } vector<pair<double, pair<int, int>>> E; for(int i = 0;i < n;++i) { for(int j = i + 1;j < n;++j) { E.push_back({dist(x[i], y[i], x[j], y[j])-r[i]-r[j], {i, j}}); } E.push_back({y[i]-r[i], {i, n}}); E.push_back({x[i]-r[i], {i, n+1}}); E.push_back({w-y[i]-r[i], {i, n+2}}); E.push_back({h-x[i]-r[i], {i, n+3}}); } DSU D(n + 5); V<string> ret(m); sort(begin(Q), end(Q), [&](array<int, 3> one, array<int, 3> two) { return one[0] < two[0]; }); sort(begin(E), end(E), [&](pair<double, pair<int, int>> one, pair<double, pair<int, int>> two) { return one.ff < two.ff; }); //debug(E); int k = 0; auto can = [&](int f, int g) { if(f == g) return true; if(f > g) swap(f, g); if(D.same_set(n+f, n+(f+1)%4))return false; if(D.same_set(n+g, n+(g+1)%4))return false; if(f == 0 && g == 3) return !D.same_set(n, n+2); else if(f+1==g) { return !D.same_set(n+(f+1)%4, n+(f+3)%4); } else { if(D.same_set(n+f, n+(f+2)%4))return false; if(D.same_set(n+(f+1)%4, n+(f+3)%4))return false; return true; } }; for(auto [R, cor, i] : Q) { while(k < sz(E) && E[k].ff < R * 2.0) { D.unite(E[k].se.ff, E[k].se.se); ++k; } string res = ""; forn(j, 4) if(can(cor, j)) res += '0' + j + 1; ret[i] = res; } forn(i, m) cout << ret[i] << '\n'; } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...