Submission #114074

#TimeUsernameProblemLanguageResultExecution timeMemory
114074MladenPBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
544 ms294148 KiB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 10000010
lld l[MAXN], r[MAXN];
int dist(int pos, int L) {
    return min(pos, L-pos);
}
lld delivery(int N, int K, int L, int pos[]) {
    for(int i = 0; i < K; i++) l[i] = dist(pos[i], L) + pos[i];
    for(int i = K; i < N; i++) l[i] = dist(pos[i], L) + pos[i] + l[i-K];

    for(int i = 0; i < K; i++) r[i] = dist(pos[N-1-i], L) + L-pos[N-1-i];
    for(int i = K; i < N; i++) r[i] = dist(pos[N-1-i], L) + L-pos[N-1-i] + r[i-K];
    lld rez = min(l[N-1], r[N-1]);
    for(int i = 0; i < N-1; i++) rez = min(rez, l[i]+r[N-2-i]);
    return rez;
}

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