# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1086540 | Pacybwoah | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 444 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "boxes.h"
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
long long delivery(int N, int K, int L, int p[]) {
vector<int> vec;
for(int i = 0; i < N; i++) vec.push_back(p[i]);
int n = vec.size();
if(n == 0) return 0;
int k = K;
int trips = n / k;
//if(n % k != 0) trips++;
auto calc = [&](int l, int r){
if(l > r) return 0;
return min(min(vec[r] * 2, (L - vec[l]) * 2), L);
};
vector<ll> pre(trips + 1);
for(int i = 0; i < trips; i++){
if(i == 0) pre[i] = calc(0, k - 1);
else pre[i] = pre[i - 1] + calc(i * k, i * k + k - 1);
}
ll suf = 0;
int lnow = trips * k, rnow = n - 1, prenow = trips - 1;
ll ans = 1e18;
while(prenow >= 0){
ans = min(ans, suf + pre[prenow] + calc(lnow, rnow));
prenow--;
lnow -= k;
rnow -= k;
suf += calc(rnow + 1, rnow + k);
}
ans = min(ans, suf + calc(lnow, rnow));
return ans;
}
// g++ -std=c++17 -o run -Wshadow -Wall -Wextra -fsanitize=undefined -fsanitize=address boxes.cpp grader.cpp
Compilation message (stderr)
# | 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... |