제출 #1105567

#제출 시각아이디문제언어결과실행 시간메모리
1105567alexander707070선물상자 (IOI15_boxes)C++14
100 / 100
518 ms333104 KiB
#include<bits/stdc++.h> #include "boxes.h" #define MAXN 10000007 using namespace std; const long long inf=1e17; int n,k,L; int team[MAXN]; long long pref[MAXN],suff[MAXN],ans; int cost(int l,int r){ int a=min(team[l],L-team[r]); int c=team[r]-team[l]; return min(2*(a+c),L); } long long delivery(int N, int K, int LL,int p[]) { n=N; k=K; L=LL; for(int i=1;i<=n;i++){ team[i]=p[i-1]; } pref[0]=0; for(int i=1;i<=n;i++){ pref[i]=pref[max(i-k,0)]+cost(max(i-k+1,1),i); } suff[n+1]=0; for(int i=n;i>=1;i--){ suff[i]=suff[min(i+k,n+1)]+cost(i,min(i+k-1,n)); } ans=inf; for(int i=0;i<=n;i++){ ans=min(ans,pref[i]+suff[i+1]); } if(n<=k)ans=min(ans,L+0LL); return ans; } /*int main(){ cout<<delivery(3,2,8,{1,2,5})<<"\n"; return 0; }*/
#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...