이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
//#include "boxes.h"
using namespace std;
const int MAXN = 1e7+5;
ll L[MAXN], R[MAXN],dis[MAXN];
void F(int P[],int n,int k,ll X[]) {
for (int i = 0; i < n; i++) {
if (i % k == k - 1) {
X[i] = 2*P[i] + ( i >= k ? X[i-k] : 0);
}
else X[i] = 2*P[i] + ( i >= k ? X[i - (i + 1)%k] : 0);
}
}
ll delivery(int n, int k, int le, int P[]) {
sort (P,P+n);
reverse(P,P+n);
for (; n > 0 && P[n-1] == 0; n--);
// if (n == 0) return 0;
reverse(P,P+n);
// ll sum_L = 0;
F(P,n,k,L);
for (int i = 0; i < n; i++) P[i] = ( (le - P[i])%le );
reverse(P,P+n);
F(P,n,k,R);
reverse(P,P+n);
for (int i = 0; i < n; i++) P[i] = ( (le - P[i])%le );
// cout << L[0] << ' ';
ll ans = min(L[n-1],R[n-1]);
// for (int i = 0; i < n; i++) {
// ans = min(ans,L[i] + (le - P[i]) - P[i] + (i + 2 <= n? R[n - i - 2] : 0 ));
// ans = min(ans,R[(n - i - 1)] + P[i] - ( le - P[i] ) + (i ? L[i-1] : 0));
// }
// ans = min(ans,L[n-1] + (le - P[n-1]) - P[n-1]);
// ans = min(ans,R[n-1] + P[0] - (le - P[0]));
for (int i = 0; i < n; i++) {
ans = min(ans,L[i] + ( i != n-1 ? R[n - i - 2] : 0) );
}
return ans;
} /*
main() {
int n,k,l;
cin >> n >> k >> l;
int p[n];
for (int i = 0; i < n ; i++)
cin >> p[i];
cout << delivery(n,k,l,p) ;
// cout <<' '<< R[0] << ' '<<R[1] <<' '<<R[2];
// 3 2 8 1 2 5
} */
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |