Submission #441811

#TimeUsernameProblemLanguageResultExecution timeMemory
441811baluteshihFountain Parks (IOI21_parks)C++17
30 / 100
574 ms48992 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define X first #define Y second #define pb push_back #define ALL(v) v.begin(), v.end() #define SZ(a) ((int)a.size()) pii operator+(const pii &a, const pii &b) { return pii(a.X + b.X, a.Y + b.Y); } vector<int> dt[200005]; int boss[200005], conn; map<pii, int> id, chair; int finds(int x) { if (x == boss[x]) return x; return boss[x] = finds(boss[x]); } bool Union(int x, int y) { x = finds(x), y = finds(y); if (x == y) return 0; boss[x] = y, --conn; return 1; } int construct_roads(vector<int> x, vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } int n = SZ(x); conn = n; iota(boss, boss + n, 0); int L = *min_element(ALL(y)); int R = *max_element(ALL(y)); for (int i = 0; i < n; ++i) { dt[y[i]].pb(i); id[pii(x[i], y[i])] = i; } for (int i = L; i <= R; i += 2) { if (dt[i].empty()) return 0; sort(ALL(dt[i]), [&](int p, int q){ return x[p] < x[q]; }); } vector<int> u, v, a, b; for (int i = L; i <= R; i += 2) { for (int p : dt[i]) { auto q = id.find(pii(x[p], y[p]) + pii(2, 0)); if (q != id.end() && finds(p) != finds(q->Y)) { Union(p, q->Y); if (chair.find(pii(x[p], y[p]) + pii(1, -1)) == chair.end()) { chair[pii(x[p], y[p]) + pii(1, -1)] = SZ(u); u.pb(p), v.pb(q->Y); a.pb(x[p] + 1); b.pb(y[p] - 1); } else { assert(chair.find(pii(x[p], y[p]) + pii(1, 1)) == chair.end()); chair[pii(x[p], y[p]) + pii(1, 1)] = SZ(u); u.pb(p), v.pb(q->Y); a.pb(x[p] + 1); b.pb(y[p] + 1); } } q = id.find(pii(x[p], y[p]) + pii(0, 2)); if (q != id.end() && finds(p) != finds(q->Y)) { Union(p, q->Y); if (chair.find(pii(x[p], y[p]) + pii(-1, 1)) == chair.end()) { chair[pii(x[p], y[p]) + pii(-1, 1)] = SZ(u); u.pb(p), v.pb(q->Y); a.pb(x[p] - 1); b.pb(y[p] + 1); } else { assert(chair.find(pii(x[p], y[p]) + pii(1, 1)) == chair.end()); chair[pii(x[p], y[p]) + pii(1, 1)] = SZ(u); u.pb(p), v.pb(q->Y); a.pb(x[p] + 1); b.pb(y[p] + 1); } } } } if (conn != 1) return 0; build(u, v, a, b); return 1; }
#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...