Submission #551100

#TimeUsernameProblemLanguageResultExecution timeMemory
5511001neFountain Parks (IOI21_parks)C++17
0 / 100
1 ms340 KiB
#include "parks.h" #include<bits/stdc++.h> using namespace std; struct edges{ int x,y,x1,y1; }; int construct_roads(std::vector<int> x, std::vector<int> y) { map<pair<int,int>,bool>mp,got,have; map<pair<int,int>,int>index; int n = (int)x.size(); for (int i = 0;i<n;++i){ mp[{x[i],y[i]}] = true; got[{x[i],y[i]}] = false; index[{x[i],y[i]}] = i; } vector<edges>ans; vector<int>dx = {2,0,-2,0}; vector<int>dy = {0,2,0,-2}; auto comp = [&](int a,int b,int c,int d){ if (a<c){ return (edges){a,b,c,d}; } else if (c < a){ return (edges){c,d,a,b}; } else if ( b < d){ return (edges){a,b,c,d}; } return (edges){c,d,a,b}; }; function<void(int,int)> dfs = [&](int u,int v){ got[{u,v}] = true; for (int i = 0;i<4;++i){ int xx = u + dx[i]; int yy = v + dy[i]; if (mp[{xx,yy}] && !got[{xx,yy}]){ ans.push_back(comp(u,v,xx,yy)); dfs(xx,yy); } } }; bool ok = true; dfs(x[0],y[0]); for (int i = 0;i<n;++i){ if (!got[{x[i],y[i]}]){ ok=false; break; } } if (!ok){ return 0; } vector<int>u,v,a,b; vector<edges>xx,yy; for (auto z:ans){ if (z.x == z.x1){ xx.push_back(z); } else { yy.push_back(z); } } sort(xx.begin(),xx.end(),[&](auto p,auto q){ return p.y < q.y; }); sort(yy.begin(),yy.end(),[&](auto p,auto q){ return p.x < q.x; }); for (int i = 0;i<(int)xx.size();++i){ u.push_back(index[{xx[i].x,xx[i].y}]); v.push_back(index[{xx[i].x1,xx[i].y1}]); if (!have[{xx[i].x1 - 1,xx[i].y1 - 1}]){ have[{xx[i].x1 - 1,xx[i].y1 - 1}] = true; a.push_back(xx[i].x1 - 1 ); b.push_back(yy[i].y1 - 1); } else { have[{xx[i].x1 + 1,xx[i].y1 - 1}] = true; a.push_back(xx[i].x1 + 1 ); b.push_back(yy[i].y1 - 1); } } for (int i = 0;i<(int)yy.size();++i){ u.push_back(index[{yy[i].x,yy[i].y}]); v.push_back(index[{yy[i].x1,yy[i].y1}]); if (!have[{xx[i].x1 - 1,xx[i].y1 + 1}]){ have[{xx[i].x1 - 1,xx[i].y1 + 1}] = true; a.push_back(xx[i].x1 - 1 ); b.push_back(yy[i].y1 + 1); } else { have[{xx[i].x1 - 1,xx[i].y1 - 1}] = true; a.push_back(xx[i].x1 - 1 ); b.push_back(yy[i].y1 - 1); } } 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...