제출 #864444

#제출 시각아이디문제언어결과실행 시간메모리
864444suiyeetRoller Coaster Railroad (IOI16_railroad)C++14
0 / 100
528 ms22364 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) #else #define debug(...) #endif const int MAXN = -1; const int inf=1000000500ll; const long long oo =1000000000000000500ll; const int MOD = (int)1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair<int,int> pi; multiset<pi> in, out; bool bad; pi findin(pi cur){ in.erase(in.find({cur.first,cur.second})); auto it=in.lower_bound({cur.second,0}); if(it==in.end()){ bad=1; return {-1,-1}; } else{ pi res=*it; in.insert({cur.first,cur.second}); return res; } } pi findout(pi cur){ out.erase(out.find({cur.second,cur.first})); auto it=out.lower_bound({cur.first,inf}); assert(it!=out.begin()); auto pre=prev(it); pi res=*pre; out.insert({cur.second,cur.first}); return res; } long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n=s.size(); for(int i=0;i<n;i++){ in.insert({s[i],t[i]}); out.insert({t[i],s[i]}); } while((int)out.size() > 1){ pi t=*out.begin(); pi pin=findin({t.second,t.first}); if(out.size() == 2){ pi t1=*in.begin(); pi t2=*next(in.begin()); if(t1.second<=t2.first || t2.first<=t1.second)return 0; } if(bad)return 1; pi pout=findout({pin.first,pin.second}); swap(pout.first,pout.second); //debug(pin.first,pin.second,pout.first,pout.second); in.erase(in.find(pin)); in.erase(in.find(pout)); out.erase(out.find({pout.second,pout.first})); out.erase(out.find({pin.second,pin.first})); pi newtrack={pout.first,pin.second}; in.insert({newtrack.first,newtrack.second}); out.insert({newtrack.second,newtrack.first}); } 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...