This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |