Submission #782507

#TimeUsernameProblemLanguageResultExecution timeMemory
782507LyricallyBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
447 ms199348 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;i++) long long pre[10000005],suf[10000005]; long long delivery(int n,int k,int l,int p[]) { rep(i,n) { if(p[i]<=l-p[i]) { if(i<k){pre[i]=min(2*p[i],l);} else{pre[i]=pre[i-k]+min(2*p[i],l);} } else{pre[i]=pre[i-1];} } for(int i=n-1;i>=0;i--) { if(p[i]>l-p[i]) { if(i+k-1<n) { suf[i]=suf[i+k]+min(2*(l-p[i]),l); } else { suf[i]=min(2*(l-p[i]),l); } } else{suf[i]=suf[i+1];} } long long res=pre[n-1]+suf[0]; rep(i,n) { if(p[i]<=l-p[i]) { if(i+k-1<n&&p[i+k-1]>l-p[i+k-1]) { res=min(res,l+(i?pre[i-1]:0)+(i+k-1<n-1?suf[i+k]:0)); } } } return res; }
#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...