Submission #176101

# Submission time Handle Problem Language Result Execution time Memory
176101 2020-01-07T23:07:49 Z mat_v Boxes with souvenirs (IOI15_boxes) C++14
100 / 100
880 ms 237404 KB
#include <bits/stdc++.h>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#include "boxes.h"
#define maxn 10000005
using namespace std;
typedef long long ll;
int n,k;
int niz[maxn];
int d;
set<int>s;
ll dist(int l, int r){
    if(l > r)swap(l, r);
    ll res = min(r - l, l + d - r);
    return res;
}

ll levi[maxn];
ll desni[maxn];
long long delivery(int N, int K, int L, int p[]) {
    n = N, k = K, d = L;
    ff(i,1,n)niz[i] = p[i - 1];
    sort(niz + 1, niz + 1 + n);
    levi[0] = 0;
    desni[n + 1] = 0;
    ff(i,1,n){
        if(i > k){
            levi[i] = levi[i - k]  + 2 * niz[i];
        }
        else levi[i] = 2 * niz[i];
        continue;
        if(k == 1 || i%k == 1){
            levi[i] = levi[i - 1] + 2*niz[i];
        }
        else{
            levi[i] = levi[i - 1] - niz[i - 1] + niz[i] - niz[i - 1] + niz[i];
        }
    }
    fb(i,n,1){
        int kol = n - i + 1;
        if(kol > k){
            desni[i] = desni[i + k] + 2*(d - niz[i]);
        }
        else desni[i] = 2*(d - niz[i]);
        continue;
        if(kol%k == 1 || k == 1){
            desni[i] = desni[i + 1] + 2*(d-niz[i]);
            //cout << i << " " << desni[i] << endl;
            //exit(0);
        }
        else{
            desni[i] = desni[i + 1] - (d-niz[i + 1]) + (d-niz[i]) - (d-niz[i + 1]) + (d-niz[i]);
        }
    }
    ll res = levi[0] + desni[1];
    ff(i,0,n){
        res = min(res, levi[i] + desni[i + 1]);
    }
    ff(i,1,n){
        res = min(res, levi[i - 1] + d + desni[i + k]);
    }
    return res;
}
/*
int aa[maxn];
int N,K,L;
int main(){
    freopen("06", "r", stdin);
    cin >> N >> K >> L;
    ff(i,0,N - 1)cin >> aa[i];
    cout << delivery(N,K,L,aa);
    return 0;
}
/*
10 5 1000
7 63 166 821 853 857 930 934 989 995
*/

Compilation message

boxes.cpp:74:1: warning: "/*" within comment [-Wcomment]
 /*
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 83 ms 25564 KB Output is correct
34 Correct 50 ms 24792 KB Output is correct
35 Correct 51 ms 25212 KB Output is correct
36 Correct 81 ms 25480 KB Output is correct
37 Correct 78 ms 25464 KB Output is correct
38 Correct 84 ms 25500 KB Output is correct
39 Correct 78 ms 25532 KB Output is correct
40 Correct 57 ms 25464 KB Output is correct
41 Correct 86 ms 25592 KB Output is correct
42 Correct 57 ms 25464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 83 ms 25564 KB Output is correct
34 Correct 50 ms 24792 KB Output is correct
35 Correct 51 ms 25212 KB Output is correct
36 Correct 81 ms 25480 KB Output is correct
37 Correct 78 ms 25464 KB Output is correct
38 Correct 84 ms 25500 KB Output is correct
39 Correct 78 ms 25532 KB Output is correct
40 Correct 57 ms 25464 KB Output is correct
41 Correct 86 ms 25592 KB Output is correct
42 Correct 57 ms 25464 KB Output is correct
43 Correct 849 ms 236036 KB Output is correct
44 Correct 516 ms 235440 KB Output is correct
45 Correct 553 ms 235432 KB Output is correct
46 Correct 814 ms 235716 KB Output is correct
47 Correct 807 ms 235676 KB Output is correct
48 Correct 840 ms 235896 KB Output is correct
49 Correct 846 ms 237404 KB Output is correct
50 Correct 577 ms 235352 KB Output is correct
51 Correct 880 ms 237364 KB Output is correct
52 Correct 585 ms 235404 KB Output is correct