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>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
const int nmax = 5e5 + 5, inf = 1e9 + 5;
vector<int> g[nmax];
bool occ[nmax];
void dfs(int node) {
if(occ[node]) return;
occ[node] = 1;
for(auto x : g[node]) {
dfs(x);
}
return;
}
long long plan_roller_coaster(vector<int> s, vector<int> t) {
t.emplace_back(0);
s.emplace_back(inf);
map<int,int> smen, nrm;
for(auto x : s)
smen[x]++;
for(auto x : t)
smen[x]--;
int edgc = 0;
int last = 0, cnt = 0;
for(auto [a, b] : smen) {
nrm[a] = cnt++;
if(edgc != 0)
g[nrm[a]].emplace_back(nrm[last]),
g[nrm[last]].emplace_back(nrm[a]);
edgc += b;
if(edgc > 0) return 0;
last = a;
}
for(int i = 0; i < sz(s); i++)
g[nrm[s[i]]].emplace_back(nrm[t[i]]),
g[nrm[t[i]]].emplace_back(nrm[s[i]]);
dfs(0);
for(auto x : s)
if(occ[nrm[x]] == 0) return 0;
for(auto x : t)
if(occ[nrm[x]] == 0) return 0;
return 3;
}
# | 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... |