Submission #1039825

#TimeUsernameProblemLanguageResultExecution timeMemory
1039825vjudge1Fountain Parks (IOI21_parks)C++17
15 / 100
222 ms39592 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; struct dsu { vector<int> e; int cc; dsu(int n) { cc=n; e=vector<int> (n, -1); } int get(int a) { if(e[a] < 0)return a; return e[a] = get(e[a]); } bool unite(int a, int b) { a=get(a), b=get(b); if(a==b)return false; cc--; if(-e[a] > -e[b])swap(a, b); e[b]+=e[a]; e[a]=b; return true; } }; int construct_roads(std::vector<int> x, std::vector<int> y) { vector<vector<int>> p(7); int n = x.size(); map<pair<int,int>, int> mp; for(int i = 0;i<n;i++) { mp[{x[i], y[i]}]=i; p[x[i]].push_back(i); } dsu d(n); vector<int> u, v; for(int i= 0;i<7;i++) { sort(p[i].begin(), p[i].end(), [&](int a, int b) { return y[a] < y[b]; }); } { int i = 6; for(int j = 1;j<(int)p[i].size();j++) { if(y[p[i][j]] == y[p[i][j-1]] + 2){ if(d.unite(p[i][j], p[i][j-1])) { v.push_back(p[i][j]); u.push_back(p[i][j-1]); } } } } { int i = 2; for(int j = 1;j<(int)p[i].size();j++) { if(y[p[i][j]] == y[p[i][j-1]] + 2){ if(d.unite(p[i][j], p[i][j-1])) { v.push_back(p[i][j]); u.push_back(p[i][j-1]); } } } } { int i = 4; for(int j = 1;j<(int)p[i].size();j++) { if(y[p[i][j]] == y[p[i][j-1]] + 2){ if(d.unite(p[i][j], p[i][j-1])) { v.push_back(p[i][j]); u.push_back(p[i][j-1]); } } } } { for(int j:p[4]) { if(mp.find({x[j]-2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]-2, y[j]}])) { u.push_back(mp[{x[j]-2, y[j]}]); v.push_back(j); } } for(int j:p[4]) { if(mp.find({x[j]+2, y[j]}) != mp.end() and d.unite(j, mp[{x[j]+2, y[j]}])) { v.push_back(mp[{x[j]+2, y[j]}]); u.push_back(j); } } } // for(int i = 0;i<(int)v.size();i++) { // cout << u[i] << " "<< v[i] << endl; // } vector<int> a, b; if(d.cc != 1)return 0; map<pair<int,int>, bool> used; for(int j = 0;j<n-1;j++) { if(x[u[j]] == x[v[j]]) { if(x[u[j]] == 2) { a.push_back(x[u[j]]-1); b.push_back(y[u[j]]+1); used[{x[u[j]]-1,y[u[j]]+1}]=1; } else if(x[u[j]] == 6) { a.push_back(x[u[j]]+1); b.push_back(y[u[j]]+1); used[{x[u[j]]+1,y[u[j]]+1}]=1; } else if(x[u[j]] == 4) { a.push_back(-1); b.push_back(-1); } } else if(x[u[j]] == 2) { a.push_back(x[u[j]]+1); b.push_back(y[u[j]]+1); used[{x[u[j]]+1, y[u[j]]+1}]=1; } else if(x[u[j]] == 4) { a.push_back(x[u[j]]+1); b.push_back(y[u[j]]-1); used[{x[u[j]]+1, y[u[j]]-1}]=1; } } for(int j = 0;j<n-1;j++) { if(a[j] == -1) { if(!used[{x[u[j]]-1, y[u[j]]+1}]) { a[j] = x[u[j]]-1; b[j] = y[u[j]]+1; used[{x[u[j]]-1, y[u[j]]+1}]=1; } else if(!used[{x[u[j]]+1, y[u[j]]+1}]) { a[j] = x[u[j]]+1; b[j] = y[u[j]]+1; used[{x[u[j]]+1, y[u[j]]+1}]=1; } else { 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...