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 "railroad.h"
using namespace std;
const int maxn = 4e5+10;
map<int, int> mp;
int soma[maxn];
bool mark[maxn];
vector<int> grafo[maxn];
void dfs(int u)
{
mark[u] = 1;
for (auto v: grafo[u])
if (!mark[v])
dfs(v);
}
long long plan_roller_coaster(vector<int> s, vector<int> t)
{
int n = (int) s.size();
mp[1] = mp[1e9] = 0;
for (int i = 0; i < n; i++)
mp[s[i]] = mp[t[i]] = 0;
int aux = 0;
for (auto &x: mp)
x.second = aux++;
vector<int> v;
for (int i = 0; i < n; i++)
{
soma[mp[s[i]]]++;
soma[mp[t[i]]]--;
v.push_back(mp[s[i]]);
v.push_back(mp[t[i]]);
grafo[mp[s[i]]].push_back(mp[t[i]]);
}
soma[mp[1]]++, soma[mp[1e9]]++;
for (int i = 0; i < aux; i++)
{
if (i) soma[i] += soma[i-1];
if (soma[i] > 0) return 1;
else if (soma[i] < 0) grafo[i].push_back(i+1);
}
dfs(0);
for (int i = 0; i < aux; i++)
if (!mark[i])
return 1;
return 0;
}
# | 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... |