Submission #158444

# Submission time Handle Problem Language Result Execution time Memory
158444 2019-10-17T05:48:13 Z davitmarg Boxes with souvenirs (IOI15_boxes) C++17
0 / 100
2 ms 504 KB
/*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 1000000000ll
#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;

int n;
LL k, m;
deque<int> pos;
LL ans;

LL delivery(int N, int K, int L, int *P)
{
    n = N;
    k = K;
    m = L;
    for (int i = 0; i < N; i++)
        if (P[i])
            pos.PB(P[i]);
    while (!pos.empty())
    {
        if (pos.size() >= 2 * k)
        {
            if (pos[k - 1] < (m - pos[pos.size() - k]))
            {
                ans += 2ll * pos[k - 1];
                for (int i = 0; i < k; i++)
                    pos.pop_front();
            }
            else
            {
                ans += 2ll * (m - pos[pos.size() - k]);
                for (int i = 0; i < k; i++)
                    pos.pop_back();
            }
        }
        else
        {
            LL add1 = 0, add2 = 0;
            add1 += min(2ll * pos[k - 1], m);
            if (k < pos.size())
                add1 += min(2ll * (m - pos[k]), m);

            add2 += min(2ll * (m - pos[pos.size() - k]), m);
            if (pos.size() - k - 1 >= 0)
                add2 += min(2ll * pos[pos.size() - k - 1], m);

            //cout << add1 << " : " << add2 << endl;
            ans += min(add1, add2);
            break;
        }
    }
    return ans;
}

#ifdef death

int main()
{
    int N, K, L;
    vector<int> pos;
    cin >> N >> K >> L;
    for (int i = 0; i < N; i++)
    {
        pos.PB(0);
        cin >> pos.back();
    }
    cout << delivery(N, K, L, pos) << endl;
    return 0;
}

#endif

/*

3 2 8
1 2 5

*/

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pos.size() >= 2 * k)
             ~~~~~~~~~~~^~~~~~~~
boxes.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (k < pos.size())
                 ~~^~~~~~~~~~~~
boxes.cpp:63:36: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
             if (pos.size() - k - 1 >= 0)
                 ~~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -