# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88695 | amiratou | Roller Coaster Railroad (IOI16_railroad) | C++14 | 0 ms | 0 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>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define fi first
#define se second
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vv vector<vector<int> >
#define pb push_back
#define INF 1555555
using namespace std;
vector<ii> vec,vec2;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
//memset(matched,-1,sizeof matched);
n = (int) s.size();
speed=s;
ex=t;
for (int i = 0; i < n; ++i){
vec2.pb({t[i],i});
vec.pb({s[i],i});
}
sort(all(vec));
int found_last=0,id;
for (int i = 0; i < n; ++i)
{
auto search=upper_bound(all(vec),make_pair(t[i],0));
if(search==vec.end()){
search--;
if(search->fi!=t[i]){if(!found_last){found_last++;tab[i]=-1;id=i;}else return INF;}
else{
tab[i]=(search-vec.begin());
//debug(tab[i]);
continue;
}
}
if(search==vec.begin()){
tab[i]=search-vec.begin();
continue;
}
search--;
if(search->fi!=t[i])search++;
tab[i]=(search-vec.begin());
}
sort(all(vec2));
for (int i = 0; i < n; ++i)
{
if((i)==(tab[vec2[i].se])||(i)==(tab[vec2[i].se]+1)||(i-1)==tab[vec2[i].se])
continue;
else return INF;
}
return 0;
//return ((solve(0)==1)?0:INF);
}