Submission #1314553

#TimeUsernameProblemLanguageResultExecution timeMemory
1314553rahidilbayramliBoxes with souvenirs (IOI15_boxes)C++20
100 / 100
398 ms274360 KiB
#include<bits/stdc++.h>
#include "boxes.h"
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
long long delivery(int N, int K, int L, int p[])
{
    ll pos[N+1];
    for(ll i = 1; i <= N; i++)
        pos[i] = p[i-1];
    ll x[N+1], y[N+1];
    x[0] = 0;
    for(ll i = 1; i <= N; i++)
    {
        if(i <= K)
            x[i] = pos[i] + min(pos[i], L - pos[i]);
        else
            x[i] = x[i-K] + pos[i] + min(pos[i], L - pos[i]);
    }
    y[N+1] = 0;
    for(ll i = N; i >= 1; i--)
    {
        if(N - i + 1 <= K)
            y[i] = (L - pos[i]) + min(pos[i], L - pos[i]);
        else
            y[i] = y[K+i] + (L - pos[i]) + min(pos[i], L - pos[i]);
    }
    ll res = min(x[N], y[1]);
    for(ll i = 1; i <= N - 1; i++)
        res = min(res, x[i] + y[i+1]);
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...