Submission #1208890

#TimeUsernameProblemLanguageResultExecution timeMemory
1208890andrejikusBoxes with souvenirs (IOI15_boxes)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

const int N = 2e5 + 3;
const ll inf = 1e18;
ll pref[N], suf[N];

static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}

static inline int _readInt() {
    int c, x, s;
    c = _read();
    while (c <= 32) c = _read();
    x = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        x *= 10;
        x += c - '0';
        c = _read();
    }
    if (s < 0) x = -x;
    return x;
}

long long delivery(int n, int k, int l, int p[]) {
    ll ans = inf;

    for (int r = 1; r <= n; r++) {
        int ost2 = r%k;
        int j = (ost2 == 0 ? k-1 : ost2-1);
        suf[j] += l-p[n-r];
    }

    for (int i = 0; i <= n; i++) {
        ll res = 0;
        int r = (n-i);
        int ost1 = i%k;
        int j = (ost1 == 0 ? k-1 : ost1-1);

        res += p[i-1];
        res += min(p[i-1], l-p[i-1]);
        res += 2*pref[j];

        if (i > 0)
            pref[j] += p[i-1];

        //dbg(pref[j], res, i);

        int ost2 = r%k;
        j = (ost2 == 0 ? k-1 : ost2-1);

        if (r > 0)
            suf[j] -= l-p[n-r];

        res += (l-p[n-r]);
        res += min(l-p[n-r], p[n-r]);
        res += 2*suf[j];

        ans = min(ans, res);
    }

    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...