# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1086559 | Pacybwoah | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 600 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++) if(p[i] > 0) vec.push_back(p[i]);
int n = vec.size();
if(n == 0) return 0;
int k = K;
int cut = n;
for(int i = 0; i < n; i++){
if(vec[i] > L / 2){
cut = i;
break;
}
}
vector<ll> dpp(n + 1, 1e18), dps(n + 2, 1e18);
dpp[0] = 0;
for(int i = 1; i <= cut; i++){
dpp[i] = dpp[max(0, i - k)] + 2 * vec[i - 1];
}
dps[n + 1] = 0;
for(int i = n; i > cut; i--){
dps[i] = dps[min(n + 1, i + k)] + 2 * (L - vec[i - 1]);
}
if(cut == n){
return dpp[n];
}
if(cut == 0){
return dps[1];
}
ll ans = dpp[cut] + dps[cut + 1];
vector<ll> pre(n + 1, 1e18);
for(int i = cut + 1; i <= n; i++) pre[i] = min(pre[i - 1], dps[i]);
for(int i = max(1, cut - k + 1); i <= cut; i++) ans = min(ans, dpp[i] + L + pre[min(n, i + k + 1)]);
//for(int i = 1; i <= n; i++) cout << dpp[i] << " " << dps[i] << "\n";
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... |