Submission #195618

# Submission time Handle Problem Language Result Execution time Memory
195618 2020-01-16T16:14:14 Z jovan_b Boxes with souvenirs (IOI15_boxes) C++17
100 / 100
848 ms 450208 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#include "boxes.h"

ll niz1[10000005];
ll dp1[10000005];
ll niz2[10000005];
ll dp2[10000005];
ll n;

long long delivery(int N, int K, int L, int p[]){
    ll l = L;
    ll k = K;
    n = N;
    for(ll i=0; i<N; i++){
        if(!p[i]) continue;
        niz1[i+1] = p[i];
        niz2[i+1] = p[i];
    }
    reverse(niz2+1, niz2+n+1);
    ll cost = 0;
    ll lcost = 0;
    for(ll i=n; i>=1; i-=k){
        lcost += 2*niz1[i];
    }
    cost = lcost;
    for(int i=1; i<=n; i++){
        if(i-k >= 0) dp1[i] += dp1[i-k];
        dp1[i] += 2*niz1[i];
    }
    for(int i=1; i<=n; i++){
        if(i-k >= 0) dp2[i] += dp2[i-k];
        dp2[i] += 2*(l-niz2[i]);
    }
    for(int i=0; i<=n; i++){
        int ost = n-k-i;
        if(ost >= 0) cost = min(cost, l+dp1[i]+dp2[ost]);
        cost = min(cost, dp1[i]+dp2[n-i]);
    }
    return min(cost, lcost);
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:38:22: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
         int ost = n-k-i;
                   ~~~^~
# 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 16 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 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 380 KB Output is correct
5 Correct 2 ms 380 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
# 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 16 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 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 412 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 428 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 380 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 3 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 16 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 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 412 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 428 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 380 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 94 ms 45316 KB Output is correct
34 Correct 52 ms 35960 KB Output is correct
35 Correct 54 ms 37596 KB Output is correct
36 Correct 78 ms 45380 KB Output is correct
37 Correct 84 ms 45440 KB Output is correct
38 Correct 83 ms 45340 KB Output is correct
39 Correct 76 ms 43804 KB Output is correct
40 Correct 57 ms 39268 KB Output is correct
41 Correct 83 ms 45376 KB Output is correct
42 Correct 59 ms 39416 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 16 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 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 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 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 412 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 428 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 380 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 94 ms 45316 KB Output is correct
34 Correct 52 ms 35960 KB Output is correct
35 Correct 54 ms 37596 KB Output is correct
36 Correct 78 ms 45380 KB Output is correct
37 Correct 84 ms 45440 KB Output is correct
38 Correct 83 ms 45340 KB Output is correct
39 Correct 76 ms 43804 KB Output is correct
40 Correct 57 ms 39268 KB Output is correct
41 Correct 83 ms 45376 KB Output is correct
42 Correct 59 ms 39416 KB Output is correct
43 Correct 827 ms 449388 KB Output is correct
44 Correct 573 ms 356448 KB Output is correct
45 Correct 599 ms 378488 KB Output is correct
46 Correct 848 ms 450184 KB Output is correct
47 Correct 829 ms 450208 KB Output is correct
48 Correct 832 ms 449400 KB Output is correct
49 Correct 751 ms 431036 KB Output is correct
50 Correct 576 ms 387300 KB Output is correct
51 Correct 842 ms 448800 KB Output is correct
52 Correct 602 ms 389912 KB Output is correct