제출 #206934

#제출 시각아이디문제언어결과실행 시간메모리
206934Kenzo_1114선물상자 (IOI15_boxes)C++14
0 / 100
5 ms376 KiB
#include<bits/stdc++.h> #include "boxes.h" using namespace std; const int MAXN = 10000010; int N, K, L, POSITIONS[MAXN], pos[MAXN]; long long int ans[MAXN]; long long int delivery(int n, int k, int l, int positions[]) { int id1 = 0, id2 = 0; for(int i = 0; i < n; i++) pos[i + 1] = positions[i]; for(int i = 1; i <= n; i++) if(pos[i] > l / 2) { id1 = i - 1; id2 = i; break; } for(int i = 1; i <= id1; i++) ans[i] = 2 * pos[i] + ans[(i / k) * k]; for(int i = n; i > id1; i--) ans[i] = 2 * (l - pos[i]) + ans[n + 1 - ((n - i + 1) / k) * k]; long long int ANS = ans[id1] + ans[id2]; id1 = (id1 / k) * k; id2 = n + 1 - ((n - id2) / k) * k; long long int ANS2 = ans[id1] + l + ans[id1 + k + 1]; long long int ANS3 = ans[id2] + l + ans[id2 - k - 1]; // printf("ans[%d](%lld) + %d + ans[%d](%lld)\n", id2, ans[id2], l, id2 - k - 1, ans[id2 - k - 1]); // printf("ans = %lld ans2 = %lld ans3 = %lld\n", ANS, ANS2, ANS3); return min(ANS, min(ANS2, ANS3)); } /* int main () { scanf("%d %d %d", &N ,&K, &L); for(int i = 0; i < N; i++) scanf("%d", &POSITIONS[i]); printf("%lld\n",delivery(N, K, L, POSITIONS)); } */ /* 4 2 8 1 2 3 5 */
#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...