이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
set<pair<int,int>> lrset;
set<pair<int,int>> rlset;
for (int i = 0; i<n; i++){
lrset.insert({s[i],t[i]});
rlset.insert({t[i],s[i]});
}
while (lrset.size()>1){
/*cout<<'\n';
for (auto p : lrset){
cout<<p.first<<' '<<p.second<<'\n';
}*/
auto el = lrset.begin();
int firstl = el->first;
auto smallestrpair = rlset.lower_bound({firstl+1,-1});
if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){
smallestrpair = rlset.lower_bound({el->second,el->first-1});
}
if (smallestrpair==rlset.begin()){
el = next(el,1);
firstl = el->first;
smallestrpair = rlset.lower_bound({firstl+1,-1});
if (smallestrpair!=rlset.begin()&&*prev(smallestrpair,1)==make_pair(el->second,el->first)){
smallestrpair = rlset.lower_bound({el->second,el->first-1});
}
if (smallestrpair==rlset.begin()){
return 1;
}
}
smallestrpair = prev(smallestrpair,1);
//merge el with smallestrpair
int fpairl = el->first;
int fpairr = el->second;
int spairl = smallestrpair->second;
int spairr = smallestrpair->first;
lrset.erase({fpairl,fpairr});
rlset.erase({fpairr,fpairl});
lrset.erase({spairl,spairr});
rlset.erase({spairr,spairl});
lrset.insert({spairl,fpairr});
rlset.insert({fpairr,spairl});
}
return 0;
}
# | 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... |