Submission #220406

#TimeUsernameProblemLanguageResultExecution timeMemory
220406davitmargBoxes with souvenirs (IOI15_boxes)C++17
20 / 100
5 ms384 KiB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int N = 200005;

int n, k;
LL m, l[N], r[N],pos[N];
LL ans=mod*mod;

LL delivery(int N, int K, int L, int* P)
{
    n = N;
    k = K;
    m = L;
    for (int i = 0; i < n; i++)
        pos[i + 1] = P[i];
    pos[n + 1] = m;

    for (int i = 1; i <= n; i++)
    {
        int id = (i - 1) / k;
        l[i] = l[id * k];
        l[i] += abs(pos[i] - pos[0]) * 2;
    }

    reverse(pos, pos + 1 + n + 1);
    for (int i = 1; i <= n; i++)
    {
        int id = (i - 1) / k;
        r[i] = r[id * k];
        r[i] += abs(pos[i] - pos[0]) * 2;
    }
    reverse(pos, pos + 1 + n + 1);

    for (int i = 0; i <= n; i++)
        ans = min(ans, l[i] + r[n - i]);

    for (int i = 0; i <= n; i++)
        ans = min(ans, l[i] + r[max(0, n - i - k)] + m);

    for (int i = 0; i <= n; i++)
        ans = min(ans, r[i] + l[max(0, n - i - k)] + m);

    return ans;
}

#ifdef death

int main()
{
    int N, K, L;
    int P[102];
    cin >> N >> K >> L;
    for (int i = 0; i < N; i++)
        cin >> P[i];
    cout << delivery(N, K, L, P) << endl;
    return 0;
}

#endif

/*

3 2 8
1 2 5

2 2 6
4 5


2 3 7
3 4

0 1 2 3 4 5 6 0
      * *
*/

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:31:40: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 LL delivery(int N, int K, int L, int* P)
                                        ^
boxes.cpp:25:11: note: shadowed declaration is here
 const int N = 200005;
           ^
#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...