Submission #147605

#TimeUsernameProblemLanguageResultExecution timeMemory
147605nandonathanielBoxes with souvenirs (IOI15_boxes)C++14
0 / 100
2 ms380 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL INF=1e18; LL dist(LL x,LL y,LL mod){ return min((y-x+mod)%mod,(x-y+mod)%mod); } LL cost(LL a,LL b,LL mod){ return dist(a,0,mod)+(b-a+mod)%mod+dist(b,0,mod); } LL delivery(int N, int K, int L, int p[]) { LL ans=INF; for(LL i=1;i<K;i++){ //i di kiri, K-i di kanan LL ret=0; if(i!=0)ret+=cost(p[0],p[i-1],L); for(LL j=i;j<N;j+=K)ret+=cost(p[j],p[min(j+K-1,(LL)N-1)],L); ans=min(ans,ret); } return ans; } /* int main() { int n,k,l,i,a[101010]; cin>>n>>k>>l; for(i=0;i<n;i++) cin>>a[i]; cout<<delivery(n,k,l,a)<<"\n"; }*/
#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...