Submission #114571

#TimeUsernameProblemLanguageResultExecution timeMemory
114571ly20Roller Coaster Railroad (IOI16_railroad)C++14
30 / 100
1074 ms26232 KiB
#include<bits/stdc++.h> using namespace std; #include "railroad.h" const int MAXN=212345; pair<int,int> v[MAXN]; set<pair<int,int> > se,ss; long long plan_roller_coaster(vector<int> e,vector<int> s) { int n=e.size(); for(int i=0;i<n;i++) { se.insert(make_pair(e[i],i));ss.insert(make_pair(s[i],i)); } long long resp1=0; int ini; int idk=(*(--ss.end())).second; ss.erase(make_pair(s[idk],idk)); //ini=e[idk]; se.erase(make_pair(e[idk],idk)); int id1=idk; idk=(*(se.begin())).second; se.erase(make_pair(e[idk],idk)); //ini=s[idk]; ss.erase(make_pair(s[idk],idk)); int id2=idk; se.insert(make_pair(e[id1],id1)); ss.insert(make_pair(s[id2],id2)); set<pair<int,int> >::iterator ite,its; ite=se.begin();its=ss.begin(); while(ite!=se.end()) { if((its->second)==(ite->second) && ++its!=ss.end()) { resp1+=max((its->first)-(ite->first),0); its--; ite++; resp1+=max((its->first)-(ite->first),0); its++; } else resp1+=max((its->first)-(ite->first),0); ite++;its++; } /*for(int i=0;i<n-1;i++) { set<pair<int,int> >::iterator id=ss.upper_bound(make_pair(ini,0)); if(id!=ss.begin())id--; idk=id->second; ss.erase(id); resp1+=max(0,s[idk]-ini); ini=e[idk]; se.erase(make_pair(e[idk],idk)); }*/ se.clear(); ss.clear(); for(int i=0;i<n;i++) { se.insert(make_pair(e[i],i));ss.insert(make_pair(s[i],i)); } idk=(*(se.begin())).second; se.erase(make_pair(e[idk],idk)); //ini=e[idk]; ss.erase(make_pair(s[idk],idk)); id1=idk; idk=(*(--ss.end())).second; ss.erase(make_pair(s[idk],idk)); //ini=s[idk]; se.erase(make_pair(e[idk],idk)); id2=idk; se.insert(make_pair(e[id2],id2)); ss.insert(make_pair(s[id1],id1)); long long resp2=0; ite=se.begin();its=ss.begin(); while(ite!=se.end()) { if((its->second)==(ite->second) && ++its!=ss.end()) { resp2+=max((its->first)-(ite->first),0); its--; ite++; resp2+=max((its->first)-(ite->first),0); its++; } else resp2+=max((its->first)-(ite->first),0); ite++;its++; } /*idk=(*(se.begin())).second; se.erase(make_pair(e[idk],idk)); ini=s[idk]; ss.erase(make_pair(s[idk],idk)); for(int i=0;i<n-1;i++) { set<pair<int,int> >::iterator id=se.lower_bound(make_pair(ini,0)); if(id==se.end())id--; idk=id->second; se.erase(id); resp2+=max(0,ini-e[idk]); ini=s[idk]; ss.erase(make_pair(s[idk],idk)); }*/ return min(resp1,resp2); } /*int main() { int n; scanf("%d",&n); vector<int> e,s; for(int i=0;i<n;i++) { int a,b; scanf("%d %d",&a,&b); e.push_back(a);s.push_back(b); } printf("%lld\n",plan_roller_coaster(e,s)); return 0; }*/

Compilation message (stderr)

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:15:6: warning: unused variable 'ini' [-Wunused-variable]
  int ini;
      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...