Submission #990122

# Submission time Handle Problem Language Result Execution time Memory
990122 2024-05-29T16:30:14 Z crafticat Boxes with souvenirs (IOI15_boxes) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

long long delivery(int N, int K, int L, int p[]) {
    vector<int> prefix(N), suffix(N);
    for (int i = 0; i < N; ++i) {
        prefix[i] = p[i] + min(p[i],L - p[i]);
        suffix[i] = L - p[i] + min(p[i], L - p[i]);
    }

    int l = -1, r = -1;
    int ans = 0;
    while (l + r < N - 1) {
        int j = (N - 2) - r - l;
        if (j == 0) break;
        if (j > K) j = K;
        if (prefix[l + j] < suffix[r + j]) {
            ans += prefix[l + j];
            l += j;
        } else {
            ans += suffix[l + j];
            r += j;
        }
    }
    return ans;
}
#if DEBUG
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

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;
}

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);
    return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -