이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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[node]){
seen[node]=1;
if(matched[i]==-1||solve(i)){
matched[node]=i;
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;
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;}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))
return INF;
}
return 0;
//return ((solve(0)==1)?0:INF);
}
# | 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... |