Submission #1203390

#TimeUsernameProblemLanguageResultExecution timeMemory
1203390AMel0nBoxes with souvenirs (IOI15_boxes)C++20
0 / 100
0 ms328 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;
    FOR(i, N) {
        if (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]);
        } else {
            if (i+K <= N) dp[i] = dp[(i+K)%N] + 2ll*((ll)L-(ll)p[i]);
            else dp[i] = 2ll*((ll)L-(ll)p[i]);
            mxR = max(mxR, dp[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...