# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
464329 | sumit_kk10 | Boxes with souvenirs (IOI15_boxes) | C++14 | 16 ms | 15988 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 <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int MOD = 1e9 + 7;
long long delivery(int N, int K, int L, int positions[]){
int n = N, k = K, l = L;
sort(positions + 1, positions + n + 1);
long long pre_dp[n + 2][k + 1], suf_dp[n + 2][k + 1];
for(int j = 1; j <= k; ++j)
pre_dp[1][j] = 2*positions[1];
for(int i = 2; i <= n; ++i){
for(int j = 1; j <= k; ++j){
pre_dp[i][j] = INT_MAX;
if(j == 1) pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][k] + 2*positions[i]);
else pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][j - 1] + 2*(positions[i] - positions[i - 1]));
}
}
for(int i = 1; i <= n; ++i){
ll x = l - positions[i];
positions[i] = x;
}
for(int j = 1; j <= k; ++j){
suf_dp[n][j] = 2*positions[n];
suf_dp[n + 1][j] = 0;
pre_dp[0][j] = 0;
}
for(int i = n - 1; i >= 1; --i){
for(int j = 1; j <= k; ++j){
suf_dp[i][j] = INT_MAX;
if(j == 1) suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][k] + 2*positions[i]);
else suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][j - 1] + 2*(positions[i] - positions[i + 1]));
}
}
ll ans = INT_MAX;
for(int i = 1; i <= n; ++i){
ll mn = INT_MAX;
for(int j = 1; j <= k; ++j)
mn = min(mn, suf_dp[i + 1][j]);
for(int j = 1; j <= k; ++j)
ans = min(ans, pre_dp[i][j] + mn);
}
return ans;
}
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... |