Submission #598583

#TimeUsernameProblemLanguageResultExecution timeMemory
598583MadokaMagicaFanFountain Parks (IOI21_parks)C++17
30 / 100
549 ms50340 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const ll inf = 1e9; const int md1 = 1e9+7; const int md2 = 998244353; #define sz(v) ((int)v.size()) #define pb push_back #define pry cout << "YES\n" #define prn cout << "NO\n" #define endl '\n' #define fst first #define scn second /* #define ONPC */ using vi = vector<int>; const ll X= 2e5+10; int p[X]; set<ll> bench; set<ll> fount; map<ll, int> fnt; int ucount; int getp(int x) { return p[x] = (p[x] == x) ? x : getp(p[x]); } ll cord(ll x, ll y) { return y * X + x; } void build (vi u, vi v, vi a, vi b); void uni(int a, int b) { a = getp(a); b = getp(b); if (a == b) return; ++ucount; p[a] = b; return; } int construct_roads(vi x, vi y) { int n = sz(x); vector<ll> q; for (int i = 0; i < n; ++i) { p[i] = i; fount.insert(cord(x[i],y[i])); fnt[(cord(x[i],y[i]))] = i; q.pb(cord(x[i],y[i])); } sort(q.begin(), q.end()); int a,b, ind, tind; vi u, v, ansa, ansb; for (int i = 0; i < n; ++i) { a = q[i] % X; b = q[i] / X; ind = fnt[q[i]]; bool chk = (fount.find(cord(a,b+2)) != fount.end()) && (fount.find(cord(a-2,b)) != fount.end()) && (fount.find(cord(a-2,b+2)) != fount.end()); if (fount.find(cord(a,b+2)) != fount.end() && !chk) { tind = fnt[cord(a,b+2)]; if (getp(ind) != getp(tind)) { if (bench.find(cord(a-1,b+1)) == bench.end()) { bench.insert(cord(a-1,b+1)); u.pb(ind); v.pb(tind); ansa.pb(a-1); ansb.pb(b+1); uni(ind,tind); } else if (bench.find(cord(a+1,b+1)) == bench.end()){ bench.insert(cord(a+1,b+1)); u.pb(ind); v.pb(tind); ansa.pb(a+1); ansb.pb(b+1); uni(ind,tind); } } } if (fount.find(cord(a+2,b)) != fount.end()) { tind = fnt[cord(a+2,b)]; if (getp(ind) != getp(tind)) { if (bench.find(cord(a+1,b-1)) == bench.end()) { bench.insert(cord(a+1,b-1)); u.pb(ind); v.pb(tind); ansa.pb(a+1); ansb.pb(b-1); uni(ind,tind); } else if (bench.find(cord(a+1,b+1)) == bench.end()){ bench.insert(cord(a+1,b+1)); u.pb(ind); v.pb(tind); ansa.pb(a+1); ansb.pb(b+1); uni(ind,tind); } } } } if (ucount != n-1) return 0; build(u, v, ansa, ansb); return 1; } #ifdef ONPC void build(vi u, vi v, vi a, vi b) { } void solve() { int n; cin >> n; vi x(n), y(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; } cout << construct_roads(x, y) << endl; } int32_t main(int argc, char **argv) { if (argc >= 2) { freopen(argv[1], "r", stdin); } else ios_base::sync_with_stdio(0);cin.tie(0); int t = 1; /* cin >> t; */ while(t--) solve(); } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...