Submission #565833

#TimeUsernameProblemLanguageResultExecution timeMemory
565833PiejanVDCFountain Parks (IOI21_parks)C++17
15 / 100
677 ms36368 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> x, std::vector<int> y) { const int n = (int)x.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({x[i], y[i]}), id[{x[i], y[i]}] = i; stack<pair<pair<int,int>, int>>st; st.push({{x[0], y[0]}, 0}); s.erase(s.find({x[0], y[0]})); 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&1}); 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.top().first; int d = st.top().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-2,y})) process(x-2, y, 2); 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); if(s.count({x-2, y})) process(x-2, y, 2); } } else { if(s.count({x+2, y})) { process(x+2, y, 0); if(s.count({x,y+2})) process(x, y+2, 3); 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, 3); if(s.count({x, y-2})) process(x, y-2, 1); } } } 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...