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 "parks.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll int
#define ins insert
#define sz size()
#define vll vector<ll>
#define sc second
using namespace std;
const int N=2e5+5;
const int inf=1e9;
map<pair<ll,ll>, ll> f;
vll xx, yy;
ll xd[4] = {0, 2, 0, -2}, yd[4] = {2, 0, -2, 0};
ll bx[2][4] = {{-1, 1, 1, -1}, {1, 1, -1, -1}};
ll by[2][4] = {{ 1, 1, -1, -1}, {1, -1, -1, 1}};
set<pair<ll,ll>> vis;
vll v,u,a,b;
ll n,c;
bool ok(ll x,ll y){
bool free = (vis.find({x, y}) == vis.end());
if(x % 2) return free;
return free && f[{x,y}];
}
void dfs(ll x, ll y){
c++;
for(ll i=0;i<4;i++){
ll nx = x + xd[i], ny = y + yd[i];
ll p = (x + y) / 2 % 2;
ll aa = x + bx[p][i], bb = y + by[p][i];
if(!ok(nx, ny) || !ok(aa, bb)) continue;
v.pb(f[{x,y}]-1);
u.pb(f[{nx,ny}]-1);
a.pb(aa);
b.pb(bb);
vis.ins({aa, bb});
vis.ins({nx, ny});
dfs(nx, ny);
}
}
int construct_roads(vector<int> X, vector<int> Y) {
n=X.size();
for(int i=0;i<(int)X.size();i++){
f[{X[i], Y[i]}] = i + 1;
}
xx.pb(0);
yy.pb(0);
for(auto i : X) xx.pb(i);
for(auto i : Y) yy.pb(i);
dfs(xx[1], yy[1]);
if(c != 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... |