Submission #836722

#TimeUsernameProblemLanguageResultExecution timeMemory
836722oscar1fRoller Coaster Railroad (IOI16_railroad)C++17
100 / 100
494 ms69180 KiB
#include<bits/stdc++.h> #include "railroad.h" using namespace std; using ll=long long; const ll MAX_TRANSFO=4*200*1000+5,INFINI=(ll)1000*1000*1000*1000*1000*1000; ll nbTransfo,rep,nbInter; ll seuil[MAX_TRANSFO],valNouv[MAX_TRANSFO],vraiVal[MAX_TRANSFO]; set<ll> listeInter; ll valInter[MAX_TRANSFO]; unordered_map<ll,ll> transfo; ll cumu[MAX_TRANSFO]; ll pere[MAX_TRANSFO]; ll find(ll pos) { if (pere[pos]!=pos) { pere[pos]=find(pere[pos]); } return pere[pos]; } ll unir(ll deb,ll fin) { if (find(deb)!=find(fin)) { pere[find(deb)]=find(fin); return 1; } return 0; } ll plan_roller_coaster(vector<int> s,vector<int> t) { nbTransfo=s.size(); for (ll i=0;i<nbTransfo;i++) { seuil[i]=s[i]; listeInter.insert(seuil[i]); valNouv[i]=t[i]; listeInter.insert(valNouv[i]); } seuil[nbTransfo]=INFINI; listeInter.insert(INFINI); valNouv[nbTransfo]=1; listeInter.insert(1); nbTransfo++; for (ll i:listeInter) { vraiVal[nbInter]=i; transfo[i]=nbInter; nbInter++; } for (ll i=0;i<nbInter;i++) { pere[i]=i; } for (ll i=0;i<nbTransfo;i++) { cumu[transfo[seuil[i]]]++; cumu[transfo[valNouv[i]]]--; unir(transfo[seuil[i]],transfo[valNouv[i]]); } vector<pair<ll,ll>> distTri; for (ll i=0;i<nbInter-1;i++) { cumu[i+1]+=cumu[i]; rep+=(vraiVal[i+1]-vraiVal[i])*(max(cumu[i],(ll)0)); if (cumu[i]!=0) { unir(i+1,i); } distTri.push_back({vraiVal[i+1]-vraiVal[i],i}); } sort(distTri.begin(),distTri.end()); for (auto i:distTri) { if (unir(i.second,i.second+1)==1) { rep+=i.first; } } return rep; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...