# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124699 | zubec | Roller Coaster Railroad (IOI16_railroad) | C++14 | 331 ms | 45304 KiB |
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 "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 400100;
vector <int> g[N];
bool used[N];
void dfs(int v){
used[v] = 1;
for (int i = 0; i < g[v].size(); i++){
int to = g[v][i];
if (!used[to])
dfs(to);
}
}
int dp[N];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
vector <int> zhat;
s.push_back(1e9);
t.push_back(1);
for (int i = 0; i < s.size(); i++){
zhat.push_back(s[i]);
zhat.push_back(t[i]);
}
sort(zhat.begin(), zhat.end());
zhat.erase(unique(zhat.begin(), zhat.end()), zhat.end());
for (int i = 0; i < s.size(); i++){
int ss = lower_bound(zhat.begin(), zhat.end(), s[i])-zhat.begin();
int tt = lower_bound(zhat.begin(), zhat.end(), t[i])-zhat.begin();
--dp[ss];
++dp[tt];
g[ss].push_back(tt);
}
int cur = 0;
for (int i = 0; i < zhat.size(); i++){
cur += dp[i];
if (cur < 0)
return 123;
if (cur > 0 && i > 0){
g[i-1].push_back(i);
}
}
dfs(0);
for (int i = 0; i < zhat.size(); i++)
if (!used[i])
return 123;
return 0;
}
Compilation message (stderr)
# | 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... |