Submission #451963

#TimeUsernameProblemLanguageResultExecution timeMemory
451963vectorFountain Parks (IOI21_parks)C++17
100 / 100
845 ms49188 KiB
#include "parks.h" #include <bits/stdc++.h> #define SIZE 200001 using namespace std; struct point { int x, y, idx; }; set<pair<int, int> > vis; map<pair<int, int>, int> fnt; point p[SIZE]; int root[SIZE], cnt; int dx[5][3]= { { 1, 1 }, { 1, -1 }, { -1, 1 }, { -1, -1 } }; int Find(int x) { if (x==root[x]) return x; return root[x]=Find(root[x]); } void Union(int x, int y) { if (Find(x)==Find(y)) return; root[root[y]]=root[x], cnt++; } bool comp1(point a, point b) { if (a.x==b.x) return a.y<b.y; return a.x<b.x; } bool comp2(point a, point b) { if (a.y==b.y) return a.x<b.x; return a.y<b.y; } int construct_roads(vector<int> X, vector<int> Y) { int N=X.size(); for (int i=0; i<N; i++) { p[i].x=X[i], p[i].y=Y[i], p[i].idx=i, root[i]=i; fnt.insert({{X[i], Y[i]}, i}); } sort(p, p+N, comp1); for (int i=0; i<N-1; i++) if (p[i].x==p[i+1].x && p[i].y==p[i+1].y-2) Union(p[i].idx, p[i+1].idx); sort(p, p+N, comp2); for (int i=0; i<N-1; i++) if (p[i].y==p[i+1].y && p[i].x==p[i+1].x-2) Union(p[i].idx, p[i+1].idx); if (cnt!=N-1) return 0; int bx, by; vector<int> u, v, a, b; for (int i=0; i<N; i++) for (int j=0; j<4; j++) { bx=p[i].x+dx[j][0], by=p[i].y+dx[j][1]; if (vis.find({bx, by})==vis.end()) { vis.insert({bx, by}); if ((bx+by)%4==0) { if (fnt.find({bx-1, by-1})!=fnt.end() && fnt.find({bx-1, by+1})!=fnt.end()) u.push_back(fnt[{bx-1, by-1}]), v.push_back(fnt[{bx-1, by+1}]), a.push_back(bx), b.push_back(by); else if (fnt.find({bx+1, by-1})!=fnt.end() && fnt.find({bx+1, by+1})!=fnt.end()) u.push_back(fnt[{bx+1, by-1}]), v.push_back(fnt[{bx+1, by+1}]), a.push_back(bx), b.push_back(by); } else { if (fnt.find({bx-1, by-1})!=fnt.end() && fnt.find({bx+1, by-1})!=fnt.end()) u.push_back(fnt[{bx-1, by-1}]), v.push_back(fnt[{bx+1, by-1}]), a.push_back(bx), b.push_back(by); else if (fnt.find({bx-1, by+1})!=fnt.end() && fnt.find({bx+1, by+1})!=fnt.end()) u.push_back(fnt[{bx-1, by+1}]), v.push_back(fnt[{bx+1, by+1}]), a.push_back(bx), b.push_back(by); } } } 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...