Submission #1340699

#TimeUsernameProblemLanguageResultExecution timeMemory
1340699nagorn_phBoxes with souvenirs (IOI15_boxes)C++20
100 / 100
350 ms196108 KiB
#include "boxes.h"
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pii pair <int, int>
#define tiii tuple <int, int, int>
#define tiiii tuple <int, int, int, int>
#define emb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
#define matrix vector <vector <int>>
#define mat(n, m) vector <vector <int>> (n, vector <int> (m));

using namespace std;

int delivery(int32_t n, int32_t k, int32_t l, int32_t pos[]) {
    vector <int> pref(n + 2), suf(n + 2);
    for (int i = 0; i < n; i++) {
        int idx = i + 1;
        pref[idx] = pref[max(idx - k, 0ll)] + min((int)l, 2ll * pos[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
        int idx = n - i;
        suf[idx] = suf[max(idx - k, 0ll)] + min((int)l, 2ll * (l - pos[i]));
    }
    // for (int i = 0; i <= n; i++) cout << pref[i] << ", " << suf[i] << "\n";
    int ans = 1e18;
    for (int i = 0; i <= n; i++) {
        ans = min(ans, pref[i] + suf[n - i]);
    }
    return ans;
}
#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...