제출 #276941

#제출 시각아이디문제언어결과실행 시간메모리
276941eohomegrownappsRoller Coaster Railroad (IOI16_railroad)C++14
30 / 100
832 ms23416 KiB
#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(); multiset<pair<int,int>> lrset; multiset<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; //cout<<fpairl<<' '<<fpairr<<' '<<spairl<<' '<<spairr<<'\n'; lrset.erase(lrset.find({fpairl,fpairr})); rlset.erase(rlset.find({fpairr,fpairl})); lrset.erase(lrset.find({spairl,spairr})); rlset.erase(rlset.find({spairr,spairl})); lrset.insert({spairl,fpairr}); rlset.insert({fpairr,spairl}); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...