제출 #646820

#제출 시각아이디문제언어결과실행 시간메모리
646820Alex_tz307선물상자 (IOI15_boxes)C++17
100 / 100
452 ms196216 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; const int64_t INF = 1e18L; void minSelf(int64_t &x, int64_t y) { if (y < x) { x = y; } } long long delivery(int n, int k, int L, int p[]) { vector<int64_t> l(n + 1), r(n + 2); /// l[i] =def= costul minim sa livrez 1..i mergand doar la dreapta cand livrez si intorcandu-ma la inceput in ce directie vreau /// Analog r[i] in sens invers for (int i = 1; i <= n; ++i) { int last = max(0, i - k); /// mereu va fi optim sa aleg ultimii k si nu mai putin, pentru a parcurge o distanta mai mica inapoi inaintea lor, analog si in sens invers l[i] = l[last] + p[i - 1] + min(p[i - 1], L - p[i - 1]); } for (int i = n; i > 0; --i) { int nxt = min(n + 1, i + k); r[i] = r[nxt] + (L - p[i - 1]) + min(p[i - 1], L - p[i - 1]); } int64_t best = INF; for (int i = 0; i <= n; ++i) { minSelf(best, l[i] + r[i + 1]); } return best; }
#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...