Submission #1120965

#TimeUsernameProblemLanguageResultExecution timeMemory
1120965SalihSahinBoxes with souvenirs (IOI15_boxes)C++14
10 / 100
2 ms512 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; #include "boxes.h" const long long inf = 1e18; long long delivery(int N, int K, int L, int p[]) { vector<long long> pos(N); for(int i = 0; i < N; i++){ pos[i] = p[i]; } vector<long long> dpl(N+1), dpr(N+1); for(int i = 1; i <= N; i++){ if(i < K) dpl[i] = pos[i-1] * 2; else dpl[i] = dpl[i - K] + pos[i-1] * 2; } for(int i = 1; i <= N; i++){ if(i < K) dpr[i] = (L - pos[N-i]) * 2; else dpr[i] = dpr[i - K] + (L - pos[N-i]) * 2; } int llim = 0, rlim = N; for(int i = 0; i < N; i++){ if(pos[i] <= L/2) llim = i; if(rlim < 0 && pos[i] >= (L+1)/2) rlim = i; } long long ans = inf; for(int l = max(0, llim - K - 1); l <= min(N, llim + K + 1); l++){ for(int r = max(0, (N - rlim) - K - 1); r <= min(N, (N - rlim) + K + 1); r++){ if(l + r > N) break; long long rem = N - l - r; long long calc = dpl[l] + dpr[r] + ((rem + K - 1)/K) * L; ans = min(ans, calc); } } 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...