답안 #64042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64042 2018-08-03T08:46:27 Z Kubalionzzale 선물상자 (IOI15_boxes) C++14
100 / 100
381 ms 39552 KB
#include "boxes.h"
#include <map>
#include <iostream>
#include <algorithm>
#include <assert.h>

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];
    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];
    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;

    long long int curmin = sumleft + sumright;

    if (k == 1)
        return curmin;

    long long int curval, min = 1e17;
    int 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;

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

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

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

                if (start + k < n)
                {
                    curval += p[start] - p[start + k] * 1LL;
                    start += k;
                }
                else
                {
                    curval += p[start] * 1LL;
                    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:29:39: warning: unused variable 'leftleft' [-Wunused-variable]
         long long int sumleft = p[0], leftleft = -1;
                                       ^~~~~~~~
boxes.cpp:52:47: warning: unused variable 'leftright' [-Wunused-variable]
         long long int sumright = p[here - 1], leftright = -1;
                                               ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 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 348 KB Output is correct
7 Correct 2 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 296 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 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 252 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 348 KB Output is correct
14 Correct 2 ms 296 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 296 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 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 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 252 KB Output is correct
26 Correct 2 ms 276 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 252 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 348 KB Output is correct
14 Correct 2 ms 296 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 296 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 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 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 252 KB Output is correct
26 Correct 2 ms 276 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 38 ms 4216 KB Output is correct
34 Correct 14 ms 4216 KB Output is correct
35 Correct 14 ms 4328 KB Output is correct
36 Correct 37 ms 4204 KB Output is correct
37 Correct 41 ms 4244 KB Output is correct
38 Correct 39 ms 4264 KB Output is correct
39 Correct 36 ms 4188 KB Output is correct
40 Correct 20 ms 4232 KB Output is correct
41 Correct 38 ms 4216 KB Output is correct
42 Correct 19 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 252 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 348 KB Output is correct
14 Correct 2 ms 296 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 296 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 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 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 252 KB Output is correct
26 Correct 2 ms 276 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 38 ms 4216 KB Output is correct
34 Correct 14 ms 4216 KB Output is correct
35 Correct 14 ms 4328 KB Output is correct
36 Correct 37 ms 4204 KB Output is correct
37 Correct 41 ms 4244 KB Output is correct
38 Correct 39 ms 4264 KB Output is correct
39 Correct 36 ms 4188 KB Output is correct
40 Correct 20 ms 4232 KB Output is correct
41 Correct 38 ms 4216 KB Output is correct
42 Correct 19 ms 4188 KB Output is correct
43 Correct 371 ms 39412 KB Output is correct
44 Correct 117 ms 39416 KB Output is correct
45 Correct 156 ms 39440 KB Output is correct
46 Correct 351 ms 39416 KB Output is correct
47 Correct 381 ms 39408 KB Output is correct
48 Correct 355 ms 39472 KB Output is correct
49 Correct 316 ms 39552 KB Output is correct
50 Correct 170 ms 39512 KB Output is correct
51 Correct 350 ms 39504 KB Output is correct
52 Correct 170 ms 39536 KB Output is correct