Submission #624897

#TimeUsernameProblemLanguageResultExecution timeMemory
624897bruceccccccBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
860 ms293872 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e7+5; ll f[MAXN], b[MAXN]; ll delivery(int N, int K, int L, int p[]) { fill(f, f+MAXN, -1); fill(b, b+MAXN, -1); int i = 0; while (i < N && f[i] == -1) { f[i] = p[i] + min(p[i], L - p[i]); for (int j = i + K; j < N; j += K) { f[j] = f[j-K] + p[j] + min(p[j], L - p[j]); } i++; } i = N-1; while (i >= 0 && b[i] == -1) { b[i] = L - p[i] + min(p[i], L - p[i]); for (int j = i - K; j >= 0; j -= K) { b[j] = b[j+K] + L - p[j] + min(p[j], L - p[j]); } i--; } ll ans = min(f[N-1], b[0]); i=0; for (; i < N - 1; i++) { ans = min(ans, f[i] + b[i+1]); } 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...