Submission #567546

#TimeUsernameProblemLanguageResultExecution timeMemory
567546PiejanVDCFountain Parks (IOI21_parks)C++17
55 / 100
959 ms37436 KiB
#include <bits/stdc++.h> #include "parks.h" using namespace std; void build(vector<int>u, vector<int>v, vector<int>a, vector<int>b); int construct_roads(std::vector<int> xx, std::vector<int> yy) { const int n = (int)xx.size(); set<pair<int,int>>s; set<pair<int,int>>t; map<pair<int,int>,int>id; for(int i = 0 ; i < n ; i++) s.insert({xx[i], yy[i]}), id[{xx[i], yy[i]}] = i; int F,S; for(int i = 0 ; i < n ; i++) { if(!s.count({xx[i]-2, yy[i]})) F = xx[i], S = yy[i]; } queue<pair<pair<int,int>, int>>st; st.push({{F, S}, 0}); s.erase(s.find({F, S})); vector<int>u,v,a,b; auto process = [&] (int X, int Y, int T) -> void { s.erase(s.find({X,Y})); u.push_back(id[{X,Y}]); st.push({{X, Y}, T}); if(T == 0) { v.push_back(id[{X-2,Y}]); if(!t.count({X-1, Y+1})) t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1); else t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1); } else if(T == 1) { v.push_back(id[{X,Y+2}]); if(!t.count({X+1, Y+1})) t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1); else t.insert({X-1, Y+1}), a.push_back(X-1), b.push_back(Y+1); } else if(T == 2) { v.push_back(id[{X+2,Y}]); if(!t.count({X+1, Y-1})) t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1); else t.insert({X+1, Y+1}), a.push_back(X+1), b.push_back(Y+1); } else { v.push_back(id[{X,Y-2}]); if(!t.count({X-1, Y-1})) t.insert({X-1, Y-1}), a.push_back(X-1), b.push_back(Y-1); else t.insert({X+1, Y-1}), a.push_back(X+1), b.push_back(Y-1); } }; int cnt = 0; while(!st.empty()) { auto [x,y] = st.front().first; int d = st.front().second; st.pop(); cnt++; if(d == 0) { if(s.count({x, y+2})) { process(x, y+2, 3); if(s.count({x+2, y})) process(x+2, y, 0); if(s.count({x, y-2})) process(x, y-2, 1); } else { if(s.count({x, y-2})) process(x, y-2, 1); if(s.count({x+2, y})) process(x+2, y, 0); } } else if(d == 1) { if(s.count({x+2, y})) { process(x+2, y, 0); if(s.count({x, y-2})) process(x, y-2, 1); if(s.count({x-2, y})) process(x-2, y, 2); } else { if(s.count({x-2, y})) process(x-2, y, 2); if(s.count({x, y-2})) process(x, y-2, 1); } } else if(d == 2) { if(s.count({x, y-2})) { process(x, y-2, 1); if(s.count({x-2, y})) process(x-2, y, 2); if(s.count({x, y+2})) process(x, y+2, 3); } else { if(s.count({x, y+2})) process(x, y+2, 3); if(s.count({x-2, y})) process(x-2, y, 2); } } else { if(s.count({x-2, y})) { process(x-2, y, 2); if(s.count({x, y+2})) process(x, y+2, 3); if(s.count({x+2, y})) process(x+2, y, 0); } else { if(s.count({x+2, y})) process(x+2, y, 0); if(s.count({x, y+2})) process(x, y+2, 3); } } } if(cnt < n) 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...