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 15
using namespace std;
vector<ii> vec;
v speed,ex;
int tab[200005],n,matched[200005];
bool seen[200005];
bool solve(int node){
for (int i = tab[node]; i < n; ++i)
{
if(!seen[vec[i].se]&&vec[i].se!=node){
seen[vec[i].se]=1;
if(matched[vec[i].se]==-1||solve(vec[i].se)){
matched[vec[i].se]=node;
return 1;
}
seen[node]=0;
}
}
return 0;
}
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)
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());
}
for (int i = 0; i < n; ++i)
{
if(!solve(i)&&i!=id)
return INF;
}
return 0;
//return ((solve(0)==1)?0:INF);
}
Compilation message (stderr)
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:67:18: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(!solve(i)&&i!=id)
~~~~~~~~~^~~~~~~
# | 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... |