Submission #64030

# Submission time Handle Problem Language Result Execution time Memory
64030 2018-08-03T08:29:12 Z Kubalionzzale Boxes with souvenirs (IOI15_boxes) C++14
35 / 100
2 ms 436 KB
#include "boxes.h"
#include <map>
#include <iostream>
#include <algorithm>

long long delivery(int n, int k, int l, int p[]) {

    if (n == 1)
    {
        return std::min(p[0] * 2LL, (l - p[0]) * 2LL);
    }

    int here = n;
    for (int i = 0; i < n; ++i)
    {
        if (p[i] > l - p[i] && here == n)
        {
            here = i;
        }
        if (i >= here)
        {
            p[i] = l - p[i];
        }
    }

    if (here == 0)
    {
        long long int sumleft = p[0], leftleft = -1;
        int cur = k - 1;

        for (int i = 1; i < n; ++i)
        {
            if (cur == 0)
            {
                sumleft += p[i - 1] + p[i] * 1LL;
                cur = k - 1;
            }
            else
            {
                sumleft += p[i - 1] - p[i] * 1LL;
                --cur;
            }
        }

        sumleft += p[n - 1] * 1LL;

        return sumleft;
    }
    else if (here == n)
    {
        long long int sumright = p[here - 1], leftright = -1;
        int cur = k - 1;

        for (int i = here - 2; i >= 0; --i)
        {
            if (cur == 0)
            {
                sumright += p[i + 1] + p[i] * 1LL;
                cur = k - 1;
            }
            else
            {
                sumright += p[i + 1] - p[i] * 1LL;
                --cur;
            }
        }

        sumright += p[0] * 1LL;

        return sumright;
    }

    long long int sumleft = p[here - 1], leftleft = -1;
    int cur = k - 1;

    for (int i = here - 2; i >= 0; --i)
    {
        if (cur == 0)
        {
            sumleft += p[i + 1] + p[i] * 1LL;
            cur = k - 1;
        }
        else
        {
            sumleft += p[i + 1] - p[i] * 1LL;
            --cur;
        }
    }

    sumleft += p[0] * 1LL;

    long long int sumright = p[here], leftright = -1;
    cur = k - 1;

    for (int i = here + 1; i < n; ++i)
    {
        if (cur == 0)
        {
            sumright += p[i - 1] + p[i] * 1LL;
            cur = k - 1;
        }
        else
        {
            sumright += p[i - 1] - p[i] * 1LL;
            --cur;
        }
    }

    sumright += p[n - 1] * 1LL;
    leftright = cur;

    long long int curmin = sumleft + sumright;

    if (k == 1)
        return curmin;

    long long int curval, min = 1e17;
    int where = std::max(here - k + 1, 0), start;
    for (int i = std::max(here - k + 1, 0);; ++i)
    {
        if (i >= here)
            break;
        if (i + k - 1 >= n)
            break;

        curval = l;

        if (i != 0)
        {
            start = i - 1;
            curval += p[start] * 1LL;

            while (1)
            {
                curval += p[start] * 2LL;

                if (start - k >= 0)
                {
                    curval += p[start] - p[start - k] * 1LL;
                    start -= k;
                }
                else
                {
                    curval += p[start];
                    break;
                }
            }
        }
        if (i + k - 1 < n - 1)
        {
            start = i + k;

            curval += p[start] * 1LL;

            while (1)
            {
                curval += p[start] * 2LL;

                if (start + k < n)
                {
                    curval += p[start] - p[start + k] * 1LL;
                    start -= k;
                }
                else
                {
                    curval += p[start];
                    break;
                }
            }
        }

        if (curval < min)
            min = curval;
    }

    return std::min(curmin, min);
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:28:39: warning: unused variable 'leftleft' [-Wunused-variable]
         long long int sumleft = p[0], leftleft = -1;
                                       ^~~~~~~~
boxes.cpp:51:47: warning: unused variable 'leftright' [-Wunused-variable]
         long long int sumright = p[here - 1], leftright = -1;
                                               ^~~~~~~~~
boxes.cpp:73:42: warning: unused variable 'leftleft' [-Wunused-variable]
     long long int sumleft = p[here - 1], leftleft = -1;
                                          ^~~~~~~~
boxes.cpp:92:39: warning: variable 'leftright' set but not used [-Wunused-but-set-variable]
     long long int sumright = p[here], leftright = -1;
                                       ^~~~~~~~~
boxes.cpp:118:9: warning: unused variable 'where' [-Wunused-variable]
     int where = std::max(here - k + 1, 0), start;
         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 276 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 276 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Runtime error 2 ms 436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 276 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Runtime error 2 ms 436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 276 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Runtime error 2 ms 436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -