Submission #1203392

#TimeUsernameProblemLanguageResultExecution timeMemory
1203392AMel0nBoxes with souvenirs (IOI15_boxes)C++20
0 / 100
1 ms392 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FOR(i,N) for(ll i = 0; i < N; i++)
#define all(x) (x).begin(), (x).end()
// #define F first 
// #define S second

#include "boxes.h"

ll delivery(int N, int K, int L, int p[]) {
    // never optimal to take more than one full circle

    vector<ll> dp(N+1);
    ll mxL= 0, mxR = 0;
    ll i = 0;
    while((ll)p[i] <= L/2) {
        if (i-K >= 0) dp[i] = dp[i-K] + 2ll*(ll)p[i];
        else dp[i] = 2ll*(ll)p[i];
        mxL = max(mxL, dp[i]);
        i++;
    }
    i = N-1;
    while((ll)p[i] > L/2) {
        if (i+K < N) dp[i] = dp[i+K] + 2ll*((ll)L-(ll)p[i]);
        else dp[i] = 2ll*((ll)L-(ll)p[i]);
        mxR = max(mxR, dp[i]);
        i--;
    }

    ll res = mxL + mxR;
    FOR(i, N) {
        if (i+K+1 <= N && p[i] <= L/2 && p[i+K] > L/2) res = min(res, L + dp[i] + dp[i+K+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...