Submission #337079

#TimeUsernameProblemLanguageResultExecution timeMemory
337079blueBoxes with souvenirs (IOI15_boxes)C++11
35 / 100
1 ms384 KiB
#include "boxes.h"
#include <iostream>
using namespace std;

//#teams, capacity, #sections, position of each team
long long delivery(int N, int K, int L, int positions[])
{
    long long dp_inc[N]; //minimum time needed to cover all 0, 1, ... i and end up at positions[i]

    dp_inc[0] = positions[0];
    /*for(int i = 1; i < N; i++)
    {
        if(i % K == 0)
        {
            dp_inc[i] = dp_inc[i-1] + positions[i-1] + positions[i];
        }
        else
        {
            dp_inc[i] = dp_inc[i-1] + (positions[i] - positions[i-1]);
        }
    }*/
    for(int i = 1; i < K; i++)
    {
        dp_inc[i] = positions[i];
    }
    for(int i = K; i < N; i++)
    {
        dp_inc[i] = dp_inc[i - K] + positions[i - K] + positions[i];
    }

    // for(int i = 0; i < N; i++) cout << dp_inc[i] << ' ';
    // cout << '\n';

    long long dp_dec[N];

    dp_dec[N-1] = L - positions[N-1];
    /*for(int i = N-2; i >= 0; i--)
    {
        if((N - 1 - i) % K == 0)
        {
            dp_dec[i] = dp_dec[i+1] + (L - positions[i+1]) + (L - positions[i]);
        }
        else
        {
            dp_dec[i] = dp_dec[i+1] + (positions[i+1] - positions[i]);
        }
    }*/
    for(int i = N-2; i > N-K-1; i--)
    {
        dp_dec[i] = L - positions[i];
    }
    for(int i = N-K-1; i >= 0; i--)
    {
        dp_dec[i] = dp_dec[i + K] + (L - positions[i + K]) + (L - positions[i]);
    }


    //for(int i = 0; i < N; i++) cout << dp_dec[i] << ' ';
    //cout << '\n';

    long long res = (long long)(1000 * 1000 * 1000) * (long long)(1000 * 1000 * 1000);
    for(int i = 0; i < N-1; i++)
        res = min(res, dp_inc[i] + dp_dec[i+1] + positions[i] + (L - positions[i+1]));

    res = min(res, dp_inc[N-1] + min(positions[N-1], L - positions[N-1]));
    res = min(res, dp_dec[0] + min(positions[0], L - positions[0]));

    return res;
}
#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...