#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e7+5;
ll f[MAXN], b[MAXN];
ll delivery(int N, int K, int L, int p[]) {
fill(f, f+MAXN, -1);
fill(b, b+MAXN, -1);
int i = 0;
while (i < N && f[i] == -1) {
f[i] = p[i] + min(p[i], L - p[i]);
for (int j = i + K; j < N; j += K) {
f[j] = f[j-K] + p[j] + min(p[j], L - p[j]);
}
i++;
}
i = N-1;
while (i >= 0 && b[i] == -1) {
b[i] = L - p[i] + min(p[i], L - p[i]);
for (int j = i - K; j >= 0; j -= K) {
b[j] = b[j+K] + L - p[j] + min(p[j], L - p[j]);
}
i--;
}
ll ans = min(f[N-1], b[0]);
i=0;
for (; i < N - 1; i++) {
ans = min(ans, f[i] + b[i+1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
156752 KB |
Output is correct |
2 |
Correct |
66 ms |
156820 KB |
Output is correct |
3 |
Correct |
83 ms |
156720 KB |
Output is correct |
4 |
Correct |
60 ms |
156816 KB |
Output is correct |
5 |
Correct |
71 ms |
156768 KB |
Output is correct |
6 |
Correct |
57 ms |
156832 KB |
Output is correct |
7 |
Correct |
57 ms |
156744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
156784 KB |
Output is correct |
2 |
Correct |
57 ms |
156788 KB |
Output is correct |
3 |
Correct |
62 ms |
156800 KB |
Output is correct |
4 |
Correct |
58 ms |
156776 KB |
Output is correct |
5 |
Correct |
65 ms |
156752 KB |
Output is correct |
6 |
Correct |
68 ms |
156804 KB |
Output is correct |
7 |
Correct |
55 ms |
156836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
156732 KB |
Output is correct |
2 |
Correct |
62 ms |
156724 KB |
Output is correct |
3 |
Correct |
60 ms |
156812 KB |
Output is correct |
4 |
Correct |
61 ms |
156776 KB |
Output is correct |
5 |
Correct |
63 ms |
156840 KB |
Output is correct |
6 |
Correct |
59 ms |
156764 KB |
Output is correct |
7 |
Correct |
62 ms |
156768 KB |
Output is correct |
8 |
Correct |
59 ms |
156816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
156752 KB |
Output is correct |
2 |
Correct |
66 ms |
156820 KB |
Output is correct |
3 |
Correct |
83 ms |
156720 KB |
Output is correct |
4 |
Correct |
60 ms |
156816 KB |
Output is correct |
5 |
Correct |
71 ms |
156768 KB |
Output is correct |
6 |
Correct |
57 ms |
156832 KB |
Output is correct |
7 |
Correct |
57 ms |
156744 KB |
Output is correct |
8 |
Correct |
57 ms |
156784 KB |
Output is correct |
9 |
Correct |
57 ms |
156788 KB |
Output is correct |
10 |
Correct |
62 ms |
156800 KB |
Output is correct |
11 |
Correct |
58 ms |
156776 KB |
Output is correct |
12 |
Correct |
65 ms |
156752 KB |
Output is correct |
13 |
Correct |
68 ms |
156804 KB |
Output is correct |
14 |
Correct |
55 ms |
156836 KB |
Output is correct |
15 |
Correct |
56 ms |
156732 KB |
Output is correct |
16 |
Correct |
62 ms |
156724 KB |
Output is correct |
17 |
Correct |
60 ms |
156812 KB |
Output is correct |
18 |
Correct |
61 ms |
156776 KB |
Output is correct |
19 |
Correct |
63 ms |
156840 KB |
Output is correct |
20 |
Correct |
59 ms |
156764 KB |
Output is correct |
21 |
Correct |
62 ms |
156768 KB |
Output is correct |
22 |
Correct |
59 ms |
156816 KB |
Output is correct |
23 |
Correct |
68 ms |
156796 KB |
Output is correct |
24 |
Correct |
62 ms |
156796 KB |
Output is correct |
25 |
Correct |
60 ms |
156760 KB |
Output is correct |
26 |
Correct |
59 ms |
156756 KB |
Output is correct |
27 |
Correct |
62 ms |
156720 KB |
Output is correct |
28 |
Correct |
61 ms |
156732 KB |
Output is correct |
29 |
Correct |
60 ms |
156728 KB |
Output is correct |
30 |
Correct |
57 ms |
156848 KB |
Output is correct |
31 |
Correct |
59 ms |
156740 KB |
Output is correct |
32 |
Correct |
75 ms |
156744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
156752 KB |
Output is correct |
2 |
Correct |
66 ms |
156820 KB |
Output is correct |
3 |
Correct |
83 ms |
156720 KB |
Output is correct |
4 |
Correct |
60 ms |
156816 KB |
Output is correct |
5 |
Correct |
71 ms |
156768 KB |
Output is correct |
6 |
Correct |
57 ms |
156832 KB |
Output is correct |
7 |
Correct |
57 ms |
156744 KB |
Output is correct |
8 |
Correct |
57 ms |
156784 KB |
Output is correct |
9 |
Correct |
57 ms |
156788 KB |
Output is correct |
10 |
Correct |
62 ms |
156800 KB |
Output is correct |
11 |
Correct |
58 ms |
156776 KB |
Output is correct |
12 |
Correct |
65 ms |
156752 KB |
Output is correct |
13 |
Correct |
68 ms |
156804 KB |
Output is correct |
14 |
Correct |
55 ms |
156836 KB |
Output is correct |
15 |
Correct |
56 ms |
156732 KB |
Output is correct |
16 |
Correct |
62 ms |
156724 KB |
Output is correct |
17 |
Correct |
60 ms |
156812 KB |
Output is correct |
18 |
Correct |
61 ms |
156776 KB |
Output is correct |
19 |
Correct |
63 ms |
156840 KB |
Output is correct |
20 |
Correct |
59 ms |
156764 KB |
Output is correct |
21 |
Correct |
62 ms |
156768 KB |
Output is correct |
22 |
Correct |
59 ms |
156816 KB |
Output is correct |
23 |
Correct |
68 ms |
156796 KB |
Output is correct |
24 |
Correct |
62 ms |
156796 KB |
Output is correct |
25 |
Correct |
60 ms |
156760 KB |
Output is correct |
26 |
Correct |
59 ms |
156756 KB |
Output is correct |
27 |
Correct |
62 ms |
156720 KB |
Output is correct |
28 |
Correct |
61 ms |
156732 KB |
Output is correct |
29 |
Correct |
60 ms |
156728 KB |
Output is correct |
30 |
Correct |
57 ms |
156848 KB |
Output is correct |
31 |
Correct |
59 ms |
156740 KB |
Output is correct |
32 |
Correct |
75 ms |
156744 KB |
Output is correct |
33 |
Correct |
112 ms |
160664 KB |
Output is correct |
34 |
Correct |
82 ms |
160768 KB |
Output is correct |
35 |
Correct |
90 ms |
160752 KB |
Output is correct |
36 |
Correct |
108 ms |
170552 KB |
Output is correct |
37 |
Correct |
120 ms |
170576 KB |
Output is correct |
38 |
Correct |
129 ms |
170548 KB |
Output is correct |
39 |
Correct |
101 ms |
168948 KB |
Output is correct |
40 |
Correct |
109 ms |
164400 KB |
Output is correct |
41 |
Correct |
133 ms |
170448 KB |
Output is correct |
42 |
Correct |
99 ms |
164676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
156752 KB |
Output is correct |
2 |
Correct |
66 ms |
156820 KB |
Output is correct |
3 |
Correct |
83 ms |
156720 KB |
Output is correct |
4 |
Correct |
60 ms |
156816 KB |
Output is correct |
5 |
Correct |
71 ms |
156768 KB |
Output is correct |
6 |
Correct |
57 ms |
156832 KB |
Output is correct |
7 |
Correct |
57 ms |
156744 KB |
Output is correct |
8 |
Correct |
57 ms |
156784 KB |
Output is correct |
9 |
Correct |
57 ms |
156788 KB |
Output is correct |
10 |
Correct |
62 ms |
156800 KB |
Output is correct |
11 |
Correct |
58 ms |
156776 KB |
Output is correct |
12 |
Correct |
65 ms |
156752 KB |
Output is correct |
13 |
Correct |
68 ms |
156804 KB |
Output is correct |
14 |
Correct |
55 ms |
156836 KB |
Output is correct |
15 |
Correct |
56 ms |
156732 KB |
Output is correct |
16 |
Correct |
62 ms |
156724 KB |
Output is correct |
17 |
Correct |
60 ms |
156812 KB |
Output is correct |
18 |
Correct |
61 ms |
156776 KB |
Output is correct |
19 |
Correct |
63 ms |
156840 KB |
Output is correct |
20 |
Correct |
59 ms |
156764 KB |
Output is correct |
21 |
Correct |
62 ms |
156768 KB |
Output is correct |
22 |
Correct |
59 ms |
156816 KB |
Output is correct |
23 |
Correct |
68 ms |
156796 KB |
Output is correct |
24 |
Correct |
62 ms |
156796 KB |
Output is correct |
25 |
Correct |
60 ms |
156760 KB |
Output is correct |
26 |
Correct |
59 ms |
156756 KB |
Output is correct |
27 |
Correct |
62 ms |
156720 KB |
Output is correct |
28 |
Correct |
61 ms |
156732 KB |
Output is correct |
29 |
Correct |
60 ms |
156728 KB |
Output is correct |
30 |
Correct |
57 ms |
156848 KB |
Output is correct |
31 |
Correct |
59 ms |
156740 KB |
Output is correct |
32 |
Correct |
75 ms |
156744 KB |
Output is correct |
33 |
Correct |
112 ms |
160664 KB |
Output is correct |
34 |
Correct |
82 ms |
160768 KB |
Output is correct |
35 |
Correct |
90 ms |
160752 KB |
Output is correct |
36 |
Correct |
108 ms |
170552 KB |
Output is correct |
37 |
Correct |
120 ms |
170576 KB |
Output is correct |
38 |
Correct |
129 ms |
170548 KB |
Output is correct |
39 |
Correct |
101 ms |
168948 KB |
Output is correct |
40 |
Correct |
109 ms |
164400 KB |
Output is correct |
41 |
Correct |
133 ms |
170448 KB |
Output is correct |
42 |
Correct |
99 ms |
164676 KB |
Output is correct |
43 |
Correct |
520 ms |
292780 KB |
Output is correct |
44 |
Correct |
223 ms |
215548 KB |
Output is correct |
45 |
Correct |
286 ms |
223404 KB |
Output is correct |
46 |
Correct |
548 ms |
293856 KB |
Output is correct |
47 |
Correct |
561 ms |
293760 KB |
Output is correct |
48 |
Correct |
860 ms |
293872 KB |
Output is correct |
49 |
Correct |
448 ms |
278648 KB |
Output is correct |
50 |
Correct |
289 ms |
232412 KB |
Output is correct |
51 |
Correct |
580 ms |
293564 KB |
Output is correct |
52 |
Correct |
312 ms |
235140 KB |
Output is correct |