제출 #551102

#제출 시각아이디문제언어결과실행 시간메모리
5511021ne분수 공원 (IOI21_parks)C++17
15 / 100
1029 ms116396 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; } 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}; }; vector<edges>ans; vector<int>dx = {2,0,-2,0}; vector<int>dy = {0,2,0,-2}; 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; } sort(ans.begin(),ans.end(),[&](auto xx,auto yy){ return xx.x<yy.x; }); vector<int>u,v,a,b; for (auto z:ans){ int xx = z.x1; int yy = z.y1; u.push_back(index[{z.x,z.y}]); v.push_back(index[{z.x1,z.y1}]); if (z.x == z.x1){ if (!have[{xx - 1,yy - 1}]){ have[{xx - 1,yy - 1}] = true; a.push_back(xx - 1 ); b.push_back(yy- 1); } else{ a.push_back(xx + 1); b.push_back(yy - 1); have[{xx+1,yy - 1}] = true; } } else { if (!have[{xx - 1,yy + 1}]){ have[{xx - 1,yy + 1}] = true; a.push_back(xx-1); b.push_back(yy+ 1); } else{ a.push_back(xx - 1); b.push_back(yy - 1); have[{xx - 1,yy - 1}] = true; } } } 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...