Submission #1240920

#TimeUsernameProblemLanguageResultExecution timeMemory
1240920trimkus분수 공원 (IOI21_parks)C++20
100 / 100
310 ms41012 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; struct DSU { vector<int> e; DSU (int n) { e = vector<int>(n, -1); } int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } int size(int x) { return -e[get(x)]; } bool unite(int x, int y) { 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; } }; int construct_roads(std::vector<int> x, std::vector<int> y) { int N = x.size(); const int MAXN = 2e5; vector<map<int, int>> mp(MAXN + 10); for (int i = 0; i < N; ++i) { mp[x[i]][y[i]] = i; } vector<array<int, 5>> edges; DSU dsu(N); for (int i = 0; i < N; ++i) { if (mp[x[i]].count(y[i] + 2)) { dsu.unite(i, mp[x[i]][y[i] + 2]); int j = mp[x[i]][y[i] + 2]; int ny = y[i] + 1; int nx; if (((x[i] + y[i]) / 2) & 1) { nx = x[i] - 1; } else { nx = x[i] + 1; } edges.push_back({nx, ny, x[i] + y[i], i, j}); } if (mp[x[i] + 2].count(y[i])) { dsu.unite(i, mp[x[i] + 2][y[i]]); int j = mp[x[i] + 2][y[i]]; int ny; int nx = x[i] + 1; if (((x[i] + y[i]) / 2) & 1) { ny = y[i] + 1; } else { ny = y[i] - 1; } edges.push_back({nx, ny, x[i] + y[i], i, j}); } } if (dsu.size(0) != N) return 0; sort(begin(edges), end(edges)); vector<int> u, v, a, b; for (int it = 0; it < (int)edges.size(); ++it) { int i = edges[it][3]; int j = edges[it][4]; int x = edges[it][0]; int y = edges[it][1]; if (it > 0 && x == edges[it - 1][0] && y == edges[it - 1][1]) continue; u.push_back(i); v.push_back(j); a.push_back(x); b.push_back(y); } 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...