Submission #63786

# Submission time Handle Problem Language Result Execution time Memory
63786 2018-08-02T19:04:09 Z Kubalionzzale Boxes with souvenirs (IOI15_boxes) C++14
20 / 100
2 ms 380 KB
#include "boxes.h"
#include <map>
#include <iostream>
#include <algorithm>

long long int keepleft[10000010] = { 0 }, keepright[10000010] = { 0 };

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)
    {
        int cur = k - 1;
        long long int sum = p[n - 1];
        for (int i = n - 2; i >= 0; --i)
        {
            if (cur == 0)
            {
                sum += p[i + 1] * 2LL + p[i] - p[i + 1];
                cur = k - 1;
            }
            else
            {
                sum += p[i] - p[i + 1] * 1LL;
                --cur;
            }
        }

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

        return sum + p[n - 1] * 1LL;
    }

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

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

        keepleft[i] = sumleft;
    }

    sumleft += p[here - 1];
    leftleft = cur;

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

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

        keepright[i] = sumright;
    }

    sumright += p[here];
    leftright = cur;

    long long int curmin = sumleft + sumright;
    long long int curleft = sumleft - p[here - 1];

    cur = leftleft;
    bool flag = false;
    for (int i = here; i < n; ++i)
    {
        if (cur == 0)
        {
            curleft += p[i] * 2LL + keepright[i];

            if (i == here)
            {
                curleft += (l - p[i]) * 1LL - p[i - 1];
            }
            else
            {
                curleft += p[i - 1] - p[i] * 1LL;
            }

            flag = true;
            break;
        }
        else
        {
            if (i == here)
            {
                curleft += (l - p[i]) * 1LL - p[i - 1];
            }
            else
            {
                curleft += p[i - 1] - p[i] * 1LL;
            }

            --cur;
        }
    }

    if (!flag)
    {
        curleft += p[n - 1] * 1LL;
    }

    if (leftleft == 0)
        curleft = 1e17;
    curmin = std::min(curmin, curleft);

    long long int curright = sumright - p[here] * 1LL;
    cur = leftright;
    flag = false;

    for (int i = here - 1; i >= 0; --i)
    {
        if (cur == 0)
        {
            curright += p[i] * 2LL + keepleft[i];

            if (i + 1 == here)
            {
                curright += (l - p[i + 1] * 1LL) - p[i];
            }
            else
            {
                curright += p[i + 1] - p[i] * 1LL;
            }

            flag = true;
            break;
        }
        else
        {
            if (i + 1 == here)
            {
                curright += (l - p[i + 1] * 1LL) - p[i];
            }
            else
            {
                curright += p[i + 1] - p[i] * 1LL;
            }

            --cur;
        }
    }

    if (!flag)
    {
        curright += p[0] * 1LL;
    }
    if (leftright == 0)
        curright = 1e17;
    curmin = std::min(curmin, curright);

 //   std::cout << curleft << " " << curright << "\n";

    return curmin;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:118:11: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     cur = leftleft;
           ^~~~~~~~
boxes.cpp:163:11: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     cur = leftright;
           ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 292 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 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 292 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 348 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 376 KB Output is correct
6 Incorrect 2 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 292 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 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 292 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 348 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 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 292 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 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 292 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 348 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 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 292 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 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 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 256 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 292 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 348 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 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 Halted 0 ms 0 KB -