Submission #836297

#TimeUsernameProblemLanguageResultExecution timeMemory
836297oscar1fShortcut (IOI16_shortcut)C++17
0 / 100
1 ms212 KiB
#include<bits/stdc++.h> #include "shortcut.h" using namespace std; using ll=long long; const ll MAX_SOM=3000+5,INFINI=(ll)1000*1000*1000*1000*1000*1000; ll nbSom,prixNouv,rep; ll cumu[MAX_SOM]; ll distStat[MAX_SOM]; ll calcDist(ll a,ll b) { if (a>b) { swap(a,b); } return cumu[b]-cumu[a]; } ll calcInter(ll deb,ll fin) { ll diam=0; for (ll i=deb;i<=fin;i++) { for (ll j=i+1;j<=fin;j++) { diam=max(diam,calcDist(i,j)+distStat[i]+distStat[j]); } } return diam; } ll calcDiam(ll deb,ll fin) { ll diam=0; ll tempDeb=distStat[deb],tempFin=distStat[fin]; for (ll i=0;i<deb;i++) { distStat[deb]=max(distStat[deb],calcDist(i,deb)+distStat[i]); } for (ll i=fin+1;i<nbSom;i++) { distStat[fin]=max(distStat[fin],calcDist(fin,i)+distStat[i]); } diam=max(calcInter(0,deb),calcInter(fin,nbSom-1)); for (ll a=deb;a<=fin;a++) { for (ll b=a+1;b<=fin;b++) { diam=max(diam,min(calcDist(a,b),calcDist(a,deb)+calcDist(b,fin)+prixNouv)+distStat[a]+distStat[b]); } } distStat[deb]=tempDeb; distStat[fin]=tempFin; //cout<<deb<<" "<<fin<<" "<<diam<<endl; return diam; } ll find_shortcut(int n,vector<int> l,vector<int> d,int c) { nbSom=n; prixNouv=c; for (ll i=1;i<nbSom;i++) { cumu[i]=cumu[i-1]+l[i-1]; } for (ll i=0;i<nbSom;i++) { distStat[i]=d[i]; } rep=INFINI; for (ll i=0;i<nbSom;i++) { for (ll j=i+1;j<nbSom;j++) { rep=min(rep,calcDiam(i,j)); } } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...