This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "parks.h"
int n;
VVI gp;
VPI cord;
VPI bench(int u, int v) {
int dir = -1;
if (gp[u][0] == v) dir = 0;
else if (gp[u][1] == v) dir = 1;
else if (gp[u][2] == v) dir = 2;
else if (gp[u][3] == v) dir = 3;
assert(dir != -1);
int x, y;
tie(x, y) = cord[u];
if (dir == 0) return {{x-1, y-1}, {x-1, y+1}};
if (dir == 1) return {{x-1, y+1}, {x+1, y+1}};
if (dir == 2) return {{x+1, y+1}, {x+1, y-1}};
if (dir == 3) return {{x+1, y-1}, {x-1, y-1}};
return {};
}
VPI edges;
VI vis;
void dfs(int u) {
vis[u] = 1;
for (int v : gp[u]) if (v != -1) {
if (vis[v] == 1) {
/* (u, v) is a back-edge */
} else if (vis[v] == 0) {
/* (u, v) is a span-edge */
edges.pb({u, v});
dfs(v);
}
}
vis[u] = 2;
}
void build(VPI edges, VPI benches) {
int m = edges.size();
VI ret[4];
rep(i, m) ret[0].pb(edges[i].ff);
rep(i, m) ret[1].pb(edges[i].ss);
rep(i, m) ret[2].pb(benches[i].ff);
rep(i, m) ret[3].pb(benches[i].ss);
build(ret[0], ret[1], ret[2], ret[3]);
}
int construct_roads(VI x_arg, VI y_arg) {
if (true) {
n = x_arg.size();
cord = VPI(n);
rep(i, n) cord[i] = {x_arg[i], y_arg[i]};
gp = VVI(n);
map<PII, int> mp;
rep(i, n) mp[{x_arg[i], y_arg[i]}] = i;
rep(u, n) {
int x = x_arg[u];
int y = y_arg[u];
if (mp.count({x-2, y})) {
gp[u].pb(mp[{x-2, y}]);
} else gp[u].pb(-1);
if (mp.count({x, y+2})) {
gp[u].pb(mp[{x, y+2}]);
} else gp[u].pb(-1);
if (mp.count({x+2, y})) {
gp[u].pb(mp[{x+2, y}]);
} else gp[u].pb(-1);
if (mp.count({x, y-2})) {
gp[u].pb(mp[{x, y-2}]);
} else gp[u].pb(-1);
}
}
vis = VI(n);
dfs(0);
for (int x : vis) if (x == 0) return 0;
VPI benches;
set<PII> st;
for (auto[u, v] : edges) {
for (auto[x, y] : bench(u, v)) {
if (st.count({x, y})) continue;
benches.pb({x, y});
st.insert({x, y});
break;
}
}
build(edges, benches);
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... |