# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959288 | hyakup | Roller Coaster Railroad (IOI16_railroad) | C++17 | 981 ms | 524288 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 <bits/stdc++.h>
#include "railroad.h"
using namespace std;
#define ll long long
const ll inf = 1e9 + 10;
const int maxn = 4e5 + 10;
vector<pair<int, int>> adj[maxn], aux;
vector<int> marc( maxn ), g( maxn );
void dfs( int cur ){
while( !adj[cur].empty() ){
auto [viz, id] = adj[cur].back(); adj[cur].pop_back();
marc[id] = true;
dfs( viz );
}
}
ll plan_roller_coaster( vector<int> ini, vector<int> fim ){
int n = ini.size();
for( int i = 0; i < n; i++ ){ aux.push_back({ ini[i], i + 1 }); aux.push_back({ fim[i], -(i + 1) }); }
aux.push_back({ 0, 0 });
sort( aux.begin(), aux.end());
int cont = 0;
for( int i = 1; i < aux.size(); i++ ){
auto [val, id] = aux[i];
if( aux[i - 1].first != val ) cont++;
if( id > 0 ) ini[id - 1] = cont;
else fim[-id - 1] = cont;
}
for( int i = 0; i < n; i++ ){ adj[ini[i]].push_back({fim[i], i}); g[ini[i]]++; g[fim[i]]--; }
adj[0].push_back({1, n}); g[1]--;
for( int i = 1; i <= cont; i++ ){
while( g[i] < 0 ){
adj[i].push_back({ i + 1, n });
g[i]++; g[i + 1]--;
}
if( g[i] > 0 ) return 1;
}
dfs(0);
for( int i = 0; i < n; i++ ) if( marc[i] == 0 ) return 1;
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... |