제출 #154115

#제출 시각아이디문제언어결과실행 시간메모리
154115dennisstar선물상자 (IOI15_boxes)C++11
100 / 100
1008 ms151772 KiB
#include "boxes.h"
#include <bits/stdc++.h>
#define f(x) min(L-p[x],p[x])
using namespace std;
typedef long long ll;
ll s1[10000010], s2[10000010];
long long delivery(int N, int K, int L, int p[]) {
	int i, j;
	K=min(N,K);
	for (i=0; i<K; i++) { for (j=i; j<N-1; j+=K) s1[i]+=(ll)(p[j]+f(j));  }
	for (i=N-1; i>=N-K; i--) { for (j=i; j>0; j-=K) s2[i%K]+=(ll)(L-p[j]+f(j)); }
	ll ans=min(s1[(N-1)%K]+p[N-1]+f(N-1), s2[0]+L-p[0]+f(0)), s;
	for (i=0; i<K; i++) {
		s=s2[(i+1)%K]+p[i]+f(i);
		ans=min(s, ans);
		for (j=i+K; j<N; j+=K) {
			s+=(ll)(p[j]+f(j));
			s-=(ll)(L-p[j-K+1]+f(j-K+1));
			ans=min(s,ans);
		}
	}
	for (i=N-1; i>=N-K; i--) {
		s=s1[(i+K-1)%K]+(L-p[i]+f(i));
		ans=min(s, ans);
		for (j=i-K; j>=0; j-=K) {
			s+=(ll)(L-p[j]+f(j));
			s-=(ll)(p[j+K-1]+f(j+K-1));
			ans=min(s,ans);
		}
	}
	return ans;
}
#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...