이 제출은 이전 버전의 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,vec2;
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){
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(!solve(i)&&i!=id)
// return INF;
if((n-1-i)==(n-1-tab[vec2[i].se])||(n-1-i)==(n-tab[vec2[i].se]))
continue;
else return INF;
}
return 0;
//return ((solve(0)==1)?0:INF);
}
컴파일 시 표준 에러 (stderr) 메시지
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:46:22: warning: variable 'id' set but not used [-Wunused-but-set-variable]
int found_last=0,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... |