Submission #563106

#TimeUsernameProblemLanguageResultExecution timeMemory
563106CyberSleeperBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
510 ms275428 KiB
//#include "boxes.h"
#include <bits/stdc++.h>
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x)    cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x)      x.begin(), x.end()
#define fi          first
#define se          second
#define mp          make_pair
#define pb          push_back
#define ll          long long
#define ull         unsigned long long
#define pll         pair<ll, ll>
#define pii         pair<ll, ll>
#define ld          long double
#define nl          endl
#define tb          '\t'
#define sp          ' '
#define sqr(x)      (x)*(x)
#define arr3        array<ll, 3>
using namespace std;

const ll MX=200005, MOD=1000000007, BLOCK=160, INF=1e9+7, LG=62;
const ll INFF=1000000000000000004;
const ld ERR=1e-6, pi=3.14159265358979323846;

long long delivery(int N, int K, int L, int p[]) {
    ll pref[N], suff[N], ans;
    for(int i=0; i<N; i++){
        pref[i]=min(2*p[i], L);
        if(i>=K){
            pref[i]+=pref[i-K];
        }
    }
    ans=pref[N-1];
    for(int i=N-1; i>=0; i--){
        suff[i]=min(2*(L-p[i]), L);
        if(i+K<N){
            suff[i]+=suff[i+K];
        }
        ans=min(ans, suff[i]+(i ? pref[i-1] : 0));
    }
    return ans;
}

// int main() {

//     int N, K, L, i;
//     cin >> N >> K >> L;

//     int *p = (int*)malloc(sizeof(int) * (unsigned int)N);

//     for (i = 0; i < N; i++) {
//         cin >> p[i];
//     }

//     cout << delivery(N, K, L, p) << nl;
//     return 0;
// }
#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...