제출 #276939

#제출 시각아이디문제언어결과실행 시간메모리
276939eohomegrownappsRoller Coaster Railroad (IOI16_railroad)C++14
0 / 100
869 ms23800 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(); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...