Submission #836334

#TimeUsernameProblemLanguageResultExecution timeMemory
836334oscar1fShortcut (IOI16_shortcut)C++17
31 / 100
2083 ms4308 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,DECA=(1<<12); ll nbSom,prixNouv,rep; ll cumu[MAX_SOM]; ll distStat[MAX_SOM]; ll arbreMax[2*DECA],memo[MAX_SOM][MAX_SOM]; ll calcDist(ll a,ll b) { if (a>b) { swap(a,b); } return cumu[b]-cumu[a]; } ll calcMax(ll deb,ll fin) { if (deb==fin) { return arbreMax[deb]; } if (deb%2==1) { return max(arbreMax[deb],calcMax(deb+1,fin)); } if (fin%2==0) { return max(arbreMax[fin],calcMax(deb,fin-1)); } return calcMax(deb/2,fin/2); } ll calcInter(ll deb,ll fin) { if (deb>=fin) { return 0; } if (memo[deb][fin]!=-1) { return memo[deb][fin]; } memo[deb][fin]=max(calcInter(deb+1,fin),calcMax(DECA+deb+1,DECA+fin)+distStat[deb]-cumu[deb]); return memo[deb][fin]; } ll calcDiam(ll deb,ll fin) { ll diam=max(calcInter(0,deb),calcInter(fin,nbSom-1)); 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]); } ll somGlob=cumu[fin]-cumu[deb]+prixNouv; for (ll a=deb;a<=fin;a++) { for (ll b=a+1;b<=fin;b++) { diam=max(diam,min(calcDist(a,b),somGlob-calcDist(a,b))+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; for (int i=0;i<nbSom;i++) { for (int j=0;j<nbSom;j++) { memo[i][j]=-1; } } 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]; } for (ll i=0;i<nbSom;i++) { arbreMax[DECA+i]=distStat[i]+cumu[i]; } for (ll i=DECA-1;i>0;i--) { arbreMax[i]=max(arbreMax[2*i],arbreMax[2*i+1]); } 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...