제출 #742904

#제출 시각아이디문제언어결과실행 시간메모리
742904t6twotwo분수 공원 (IOI21_parks)C++17
5 / 100
56 ms7728 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; struct dsu { int n; vector<int> p, s; dsu(int m) : n(m), p(n), s(n, 1) { iota(p.begin(), p.end(), 0); } int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return s[find(x)]; } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (s[x] > s[y]) { swap(x, y); } s[y] += s[x]; p[x] = y; } }; int construct_roads(std::vector<int> x, std::vector<int> y) { int n = x.size(); int MX = *max_element(x.begin(), x.end()); if (MX == 2) { int mn = *min_element(y.begin(), y.end()); int mx = *max_element(y.begin(), y.end()); if (mx - mn != (n - 1) * 2) { return 0; } vector<int> p(n); iota(p.begin(), p.end(), 0); sort(p.begin(), p.end(), [&](int i, int j) { return y[i] < y[j]; }); vector<int> u(n - 1), v(n - 1), a(n - 1), b(n - 1); for (int i = 0; i < n - 1; i++) { u[i] = p[i]; v[i] = p[i + 1]; a[i] = 3; b[i] = y[p[i]] + 1; } build(u, v, a, b); return 1; } if (MX == 4) { vector<array<int, 2>> a, b; for (int i = 0; i < n; i++) { if (x[i] == 2) { a.push_back({y[i], i}); } else { b.push_back({y[i], i}); } } sort(a.begin(), a.end()); sort(b.begin(), b.end()); int s = a.size(); int t = b.size(); dsu uf(n); vector<int> A, B, C, D; for (int i = 0, j = 0; i < s; i++) { while (j < t && b[j][0] < a[i][0]) { j++; } if (j < t && a[i][0] == b[j][0]) { A.push_back(a[i][1]); B.push_back(b[i][1]); C.push_back(3); D.push_back(a[i][0] + 1); uf.unite(a[i][1], b[i][1]); } } for (int i = 0; i + 1 < s; i++) { if (a[i][0] + 2 == a[i + 1][0]) { A.push_back(a[i][1]); B.push_back(a[i + 1][1]); C.push_back(1); D.push_back(a[i][1] + 1); uf.unite(a[i][1], a[i + 1][1]); } } for (int i = 0; i + 1 < t; i++) { if (b[i][0] + 2 == b[i + 1][0]) { A.push_back(b[i][1]); B.push_back(b[i + 1][1]); C.push_back(5); D.push_back(b[i][1] + 1); uf.unite(b[i][1], b[i + 1][1]); } } if (uf.size(0) != n) { return 0; } build(A, B, C, D); return 1; } return 0; }
#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...