Submission #435677

#TimeUsernameProblemLanguageResultExecution timeMemory
435677BERNARB01Fountain Parks (IOI21_parks)C++17
5 / 100
330 ms43348 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; int construct_roads(vector<int> x, vector<int> y) { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } int n = x.size(); vector<pair<int, int>> p2, p4; for (int i = 0; i < n; i++) { if (x[i] == 2) { p2.emplace_back(y[i], i); } else if (x[i] == 4) { p4.emplace_back(y[i], i); } } sort(p2.begin(), p2.end()); for (int i = 1; i < (int) p2.size(); i++) { if (p2[i].first - p2[i - 1].first > 2) { return 0; } } sort(p4.begin(), p4.end()); for (int i = 1; i < (int) p4.size(); i++) { if (p4[i].first - p4[i - 1].first > 2) { return 0; } } vector<int> u, v, a, b; for (int j = 1; j < (int) p2.size(); j++) { int i = p2[j].second; int k = p2[j - 1].second; u.push_back(k); v.push_back(i); a.push_back(1); b.push_back(y[i] - 1); } for (int j = 1; j < (int) p4.size(); j++) { int i = p4[j].second; int k = p4[j - 1].second; u.push_back(k); v.push_back(i); a.push_back(5); b.push_back(y[i] - 1); } for (int i = 0, j = 0; i < (int) p2.size(); i++) { while (j < (int) p4.size() && p4[j].first < p2[i].first) { j++; } if (j >= (int) p4.size()) { break; } if (p2[i].first == p4[j].first) { int ii = p2[i].second; int jj = p4[j].second; u.push_back(ii); v.push_back(jj); a.push_back(3); b.push_back(y[ii] - 1); } } auto dist = [&](int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }; vector<vector<int>> g(n); for (int i = 0; i < (int) u.size(); i++) { if (dist(u[i], v[i]) > 2) { assert(false); return 0; } g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } vector<int> vis(n, 0); function<void(int)> dfs = [&](int uu) { if (vis[uu]) { return; } vis[uu] = 1; for (int vv : g[uu]) { dfs(vv); } }; dfs(0); if (accumulate(vis.begin(), vis.end(), 0) == n) { build(u, v, a, b); 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...