#include <bits/stdc++.h>
#ifndef ARTHUR_LOCAL
#include "boxes.h"
#endif
using namespace std;
using ll = long long;
const int MAXN = 10000001; // increase to 10^7 for last subtask
int locs[2][MAXN]; // the locations of the souvenirs on each side of the start
ll dp[2][MAXN];
int side_count[2];
ll ans[MAXN]; // MAXK == MAXN
ll CEIL(int a, int b)
{
if(a%b == 0) return ll(a/b);
return ll(a/b) + 1LL;
}
ll delivery(int n, int k, int l, int P[])
{
// intialise things
for(int i=0; i<MAXN; i++)
{
locs[0][i]=-1;
locs[1][i]=-1;
ans[i]=1e18;
}
// do things
if(n==1) return 2LL*ll(min(P[0],l-P[0]));
side_count[0]=0;
side_count[1]=0;
for(int i=0; i<n; i++)
{
if(P[i] <= int(l/2))
{
locs[0][++side_count[0]] = P[i];
//cout << "0: " << P[i] << endl;
}
}
for(int i=n-1; i>=0; i--)
{
if(P[i] > int(l/2))
{
locs[1][++side_count[1]] = l-P[i];
}
}
for(int ind=0; ind<=1; ind++) // compute both sides of the dp
{
for(int i=1; i<=side_count[ind]; i++)
{
// calculating dp[ind][i]
dp[ind][i] = 2*locs[ind][i] + dp[ind][max(0,i-k)];
//cout << ind << " " << i << " " << dp[ind][i] << endl;
// this easy ???
}
}
// now we need do the residues (mod k) bit
// should we add the excess residue here? I think yes
for(int cut=0; cut<=side_count[0]; cut++)
{
// possibly recalculate a minimum for ans[cut % k]
ll cur = dp[0][side_count[0]-cut];
cur += ll(l)*CEIL(cut,k);
// cout << cut << " " << cur << endl;
ans[cut%k] = min(ans[cut%k], cur);
}
ll ret=1e18;
int bigk=k;
while(bigk<1000000 && bigk != 1) bigk*=k; // PROBABLY CHANGE FOR LAST SUBTASK
if(bigk==1) bigk = 1000000;
for(int cut2=0; cut2<=side_count[1]; cut2++)
{
ll cur = dp[1][side_count[1]-cut2];
cur += ll(l)*ll(int(cut2/k)) + ans[(bigk-cut2)%k];
ret = min(ret,cur);
}
if(k>=n) ret=min(ret,ll(l));
return ret;
}
#ifdef ARTHUR_LOCAL
int A[MAXN];
int main()
{
A[0]=1;
A[1]=2;
A[2]=6;
A[3]=7;
cout << delivery(4,2,8,A) << endl;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
157020 KB |
Output is correct |
2 |
Correct |
138 ms |
156932 KB |
Output is correct |
3 |
Correct |
138 ms |
156908 KB |
Output is correct |
4 |
Correct |
137 ms |
156892 KB |
Output is correct |
5 |
Correct |
138 ms |
157024 KB |
Output is correct |
6 |
Correct |
137 ms |
156952 KB |
Output is correct |
7 |
Correct |
140 ms |
156828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
156892 KB |
Output is correct |
2 |
Correct |
137 ms |
156920 KB |
Output is correct |
3 |
Correct |
138 ms |
156820 KB |
Output is correct |
4 |
Correct |
138 ms |
156936 KB |
Output is correct |
5 |
Correct |
138 ms |
156920 KB |
Output is correct |
6 |
Correct |
149 ms |
156884 KB |
Output is correct |
7 |
Correct |
147 ms |
156924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
156892 KB |
Output is correct |
2 |
Correct |
140 ms |
156836 KB |
Output is correct |
3 |
Correct |
137 ms |
156920 KB |
Output is correct |
4 |
Correct |
137 ms |
156920 KB |
Output is correct |
5 |
Correct |
137 ms |
157020 KB |
Output is correct |
6 |
Correct |
164 ms |
156920 KB |
Output is correct |
7 |
Correct |
138 ms |
156920 KB |
Output is correct |
8 |
Correct |
137 ms |
156896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
157020 KB |
Output is correct |
2 |
Correct |
138 ms |
156932 KB |
Output is correct |
3 |
Correct |
138 ms |
156908 KB |
Output is correct |
4 |
Correct |
137 ms |
156892 KB |
Output is correct |
5 |
Correct |
138 ms |
157024 KB |
Output is correct |
6 |
Correct |
137 ms |
156952 KB |
Output is correct |
7 |
Correct |
140 ms |
156828 KB |
Output is correct |
8 |
Correct |
137 ms |
156892 KB |
Output is correct |
9 |
Correct |
137 ms |
156920 KB |
Output is correct |
10 |
Correct |
138 ms |
156820 KB |
Output is correct |
11 |
Correct |
138 ms |
156936 KB |
Output is correct |
12 |
Correct |
138 ms |
156920 KB |
Output is correct |
13 |
Correct |
149 ms |
156884 KB |
Output is correct |
14 |
Correct |
147 ms |
156924 KB |
Output is correct |
15 |
Correct |
138 ms |
156892 KB |
Output is correct |
16 |
Correct |
140 ms |
156836 KB |
Output is correct |
17 |
Correct |
137 ms |
156920 KB |
Output is correct |
18 |
Correct |
137 ms |
156920 KB |
Output is correct |
19 |
Correct |
137 ms |
157020 KB |
Output is correct |
20 |
Correct |
164 ms |
156920 KB |
Output is correct |
21 |
Correct |
138 ms |
156920 KB |
Output is correct |
22 |
Correct |
137 ms |
156896 KB |
Output is correct |
23 |
Correct |
141 ms |
156864 KB |
Output is correct |
24 |
Correct |
137 ms |
156876 KB |
Output is correct |
25 |
Correct |
138 ms |
156920 KB |
Output is correct |
26 |
Correct |
140 ms |
156920 KB |
Output is correct |
27 |
Correct |
141 ms |
156920 KB |
Output is correct |
28 |
Correct |
161 ms |
157048 KB |
Output is correct |
29 |
Correct |
171 ms |
156892 KB |
Output is correct |
30 |
Correct |
141 ms |
156856 KB |
Output is correct |
31 |
Correct |
142 ms |
156860 KB |
Output is correct |
32 |
Correct |
137 ms |
156824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
157020 KB |
Output is correct |
2 |
Correct |
138 ms |
156932 KB |
Output is correct |
3 |
Correct |
138 ms |
156908 KB |
Output is correct |
4 |
Correct |
137 ms |
156892 KB |
Output is correct |
5 |
Correct |
138 ms |
157024 KB |
Output is correct |
6 |
Correct |
137 ms |
156952 KB |
Output is correct |
7 |
Correct |
140 ms |
156828 KB |
Output is correct |
8 |
Correct |
137 ms |
156892 KB |
Output is correct |
9 |
Correct |
137 ms |
156920 KB |
Output is correct |
10 |
Correct |
138 ms |
156820 KB |
Output is correct |
11 |
Correct |
138 ms |
156936 KB |
Output is correct |
12 |
Correct |
138 ms |
156920 KB |
Output is correct |
13 |
Correct |
149 ms |
156884 KB |
Output is correct |
14 |
Correct |
147 ms |
156924 KB |
Output is correct |
15 |
Correct |
138 ms |
156892 KB |
Output is correct |
16 |
Correct |
140 ms |
156836 KB |
Output is correct |
17 |
Correct |
137 ms |
156920 KB |
Output is correct |
18 |
Correct |
137 ms |
156920 KB |
Output is correct |
19 |
Correct |
137 ms |
157020 KB |
Output is correct |
20 |
Correct |
164 ms |
156920 KB |
Output is correct |
21 |
Correct |
138 ms |
156920 KB |
Output is correct |
22 |
Correct |
137 ms |
156896 KB |
Output is correct |
23 |
Correct |
141 ms |
156864 KB |
Output is correct |
24 |
Correct |
137 ms |
156876 KB |
Output is correct |
25 |
Correct |
138 ms |
156920 KB |
Output is correct |
26 |
Correct |
140 ms |
156920 KB |
Output is correct |
27 |
Correct |
141 ms |
156920 KB |
Output is correct |
28 |
Correct |
161 ms |
157048 KB |
Output is correct |
29 |
Correct |
171 ms |
156892 KB |
Output is correct |
30 |
Correct |
141 ms |
156856 KB |
Output is correct |
31 |
Correct |
142 ms |
156860 KB |
Output is correct |
32 |
Correct |
137 ms |
156824 KB |
Output is correct |
33 |
Correct |
206 ms |
178364 KB |
Output is correct |
34 |
Correct |
165 ms |
170616 KB |
Output is correct |
35 |
Correct |
165 ms |
171108 KB |
Output is correct |
36 |
Correct |
202 ms |
178564 KB |
Output is correct |
37 |
Correct |
198 ms |
178424 KB |
Output is correct |
38 |
Correct |
195 ms |
178424 KB |
Output is correct |
39 |
Correct |
191 ms |
176932 KB |
Output is correct |
40 |
Correct |
196 ms |
172408 KB |
Output is correct |
41 |
Correct |
195 ms |
178424 KB |
Output is correct |
42 |
Correct |
173 ms |
172536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
157020 KB |
Output is correct |
2 |
Correct |
138 ms |
156932 KB |
Output is correct |
3 |
Correct |
138 ms |
156908 KB |
Output is correct |
4 |
Correct |
137 ms |
156892 KB |
Output is correct |
5 |
Correct |
138 ms |
157024 KB |
Output is correct |
6 |
Correct |
137 ms |
156952 KB |
Output is correct |
7 |
Correct |
140 ms |
156828 KB |
Output is correct |
8 |
Correct |
137 ms |
156892 KB |
Output is correct |
9 |
Correct |
137 ms |
156920 KB |
Output is correct |
10 |
Correct |
138 ms |
156820 KB |
Output is correct |
11 |
Correct |
138 ms |
156936 KB |
Output is correct |
12 |
Correct |
138 ms |
156920 KB |
Output is correct |
13 |
Correct |
149 ms |
156884 KB |
Output is correct |
14 |
Correct |
147 ms |
156924 KB |
Output is correct |
15 |
Correct |
138 ms |
156892 KB |
Output is correct |
16 |
Correct |
140 ms |
156836 KB |
Output is correct |
17 |
Correct |
137 ms |
156920 KB |
Output is correct |
18 |
Correct |
137 ms |
156920 KB |
Output is correct |
19 |
Correct |
137 ms |
157020 KB |
Output is correct |
20 |
Correct |
164 ms |
156920 KB |
Output is correct |
21 |
Correct |
138 ms |
156920 KB |
Output is correct |
22 |
Correct |
137 ms |
156896 KB |
Output is correct |
23 |
Correct |
141 ms |
156864 KB |
Output is correct |
24 |
Correct |
137 ms |
156876 KB |
Output is correct |
25 |
Correct |
138 ms |
156920 KB |
Output is correct |
26 |
Correct |
140 ms |
156920 KB |
Output is correct |
27 |
Correct |
141 ms |
156920 KB |
Output is correct |
28 |
Correct |
161 ms |
157048 KB |
Output is correct |
29 |
Correct |
171 ms |
156892 KB |
Output is correct |
30 |
Correct |
141 ms |
156856 KB |
Output is correct |
31 |
Correct |
142 ms |
156860 KB |
Output is correct |
32 |
Correct |
137 ms |
156824 KB |
Output is correct |
33 |
Correct |
206 ms |
178364 KB |
Output is correct |
34 |
Correct |
165 ms |
170616 KB |
Output is correct |
35 |
Correct |
165 ms |
171108 KB |
Output is correct |
36 |
Correct |
202 ms |
178564 KB |
Output is correct |
37 |
Correct |
198 ms |
178424 KB |
Output is correct |
38 |
Correct |
195 ms |
178424 KB |
Output is correct |
39 |
Correct |
191 ms |
176932 KB |
Output is correct |
40 |
Correct |
196 ms |
172408 KB |
Output is correct |
41 |
Correct |
195 ms |
178424 KB |
Output is correct |
42 |
Correct |
173 ms |
172536 KB |
Output is correct |
43 |
Runtime error |
1134 ms |
524288 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
44 |
Halted |
0 ms |
0 KB |
- |