답안 #64032

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64032 2018-08-03T08:30:01 Z Kubalionzzale 선물상자 (IOI15_boxes) C++14
10 / 100
2 ms 380 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:117:19: warning: unused variable 'curval' [-Wunused-variable]
     long long int curval, min = 1e17;
                   ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 276 KB Output is correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 276 KB Output is correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 276 KB Output is correct
8 Incorrect 2 ms 256 KB Output isn't correct
9 Halted 0 ms 0 KB -