Submission #759481

#TimeUsernameProblemLanguageResultExecution timeMemory
759481drdilyorFountain Parks (IOI21_parks)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> #include "parks.h" using namespace std; struct DSU { int n; vector<int> parent; vector<int> size; DSU(int n) : n(n), parent(n), size(n, 1) { iota(parent.begin(), parent.end(), 0); } int get(int i) { return parent[i] == i ? i : parent[i] = get(parent[i]); } void merge(int v, int u) { v = get(v); u = get(u); if (u == v) return; if (size[v] < size[u]) swap(v, u); parent[u] = v; size[v] += size[u]; } }; int construct_roads(std::vector<int> x, std::vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } int n = x.size(); std::vector<int> u, v, a, b; map<pair<int,int>, int> ft; for (int i = 0; i < n;i ++) ft[{x[i], y[i]}] = i; set<pair<int,int>> bench; for (int i = 0; i < n; i++) { for (auto [dx, dy] : {pair{0, -2}, {0, +2}, {-2, 0}, {+2, 0}}) { pair pos{x[i]+dx, y[i]+dy}; if (!ft.count(pos)) continue; int j = ft[pos]; u.push_back(i); v.push_back(j); vector<pair<int,int>> pos_bench; if (dx) { pos_bench = {{x[i]+dx/2, y[i]+1}, {x[i]+dx/2, y[i]-1}}; } else { pos_bench = {{x[i]+1, y[i]+dy/2}, {x[i]-1, y[i]+dy/2}}; } bool done = 0; for (auto pos : pos_bench) { if (bench.count(pos) == 0) { done = 1; a.push_back(pos.first); b.push_back(pos.second); break; } } if (!done) return 0; } } DSU cc(n); for (int i = 0; i < (int)u.size(); i++) { cc.merge(u[i], v[i]); } if (cc.size[cc.get(0)] != n) 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...