#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,
std::vector<int> B, std::vector<int> E) {
int q = (int)E.size();
int n = W.size();
vector<ll>ans;
vector<pair<ll,ll> >v;
for(int i=0;i<n;i++){
v.pb({W[i],i});
}
sort(v.begin(),v.end());
for(int f=0;f<q;f++){
ll d=E[f];
vector<vector<ll> > dp ( n+5 , vector<ll> (2));
for(int i=1;i<=n;i++){
dp[i][0]=1e17;
dp[i][1]=1e17;
}
for(int i=0;i<n;i++){
int a,b,c;
a=v[i].ss;
if(i>0)b=v[i-1].ss;
if(i>1)c=v[i-2].ss;
if(i>0) {
if(abs(W[a]-W[b])<=d) dp[i+1][1]=min(dp[i+1][1],dp[i][0]-A[b]+B[b]+B[a]);
}
if(i>1) {
if(abs(W[a]-W[c])<=d) dp[i+1][1]=min(dp[i+1][1],dp[i-1][0]-A[c]+B[c]+B[a]+A[b]);
}
dp[i+1][0]=min(dp[i+1][0],min(dp[i][1],dp[i][0])+A[a]);
}
ans.pb(min(dp[n][0],dp[n][1]));
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
10244 KB |
Output is correct |
2 |
Correct |
49 ms |
10176 KB |
Output is correct |
3 |
Correct |
48 ms |
10176 KB |
Output is correct |
4 |
Correct |
57 ms |
10320 KB |
Output is correct |
5 |
Correct |
49 ms |
10236 KB |
Output is correct |
6 |
Correct |
49 ms |
10236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
10236 KB |
Output is correct |
2 |
Correct |
62 ms |
10316 KB |
Output is correct |
3 |
Correct |
56 ms |
10236 KB |
Output is correct |
4 |
Correct |
61 ms |
10324 KB |
Output is correct |
5 |
Correct |
56 ms |
10236 KB |
Output is correct |
6 |
Correct |
59 ms |
10236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
428 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
1 ms |
592 KB |
Output is correct |
5 |
Correct |
3 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
49 ms |
10244 KB |
Output is correct |
8 |
Correct |
49 ms |
10176 KB |
Output is correct |
9 |
Correct |
48 ms |
10176 KB |
Output is correct |
10 |
Correct |
57 ms |
10320 KB |
Output is correct |
11 |
Correct |
49 ms |
10236 KB |
Output is correct |
12 |
Correct |
49 ms |
10236 KB |
Output is correct |
13 |
Correct |
68 ms |
10236 KB |
Output is correct |
14 |
Correct |
62 ms |
10316 KB |
Output is correct |
15 |
Correct |
56 ms |
10236 KB |
Output is correct |
16 |
Correct |
61 ms |
10324 KB |
Output is correct |
17 |
Correct |
56 ms |
10236 KB |
Output is correct |
18 |
Correct |
59 ms |
10236 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
428 KB |
Output is correct |
24 |
Correct |
2 ms |
760 KB |
Output is correct |
25 |
Correct |
59 ms |
10316 KB |
Output is correct |
26 |
Correct |
63 ms |
10280 KB |
Output is correct |
27 |
Correct |
65 ms |
10308 KB |
Output is correct |
28 |
Correct |
64 ms |
10304 KB |
Output is correct |
29 |
Correct |
66 ms |
10252 KB |
Output is correct |
30 |
Correct |
67 ms |
10336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
10236 KB |
Output is correct |
2 |
Correct |
62 ms |
10316 KB |
Output is correct |
3 |
Correct |
56 ms |
10236 KB |
Output is correct |
4 |
Correct |
61 ms |
10324 KB |
Output is correct |
5 |
Correct |
56 ms |
10236 KB |
Output is correct |
6 |
Correct |
59 ms |
10236 KB |
Output is correct |
7 |
Execution timed out |
2068 ms |
11160 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
592 KB |
Output is correct |
4 |
Correct |
2 ms |
760 KB |
Output is correct |
5 |
Correct |
1 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
49 ms |
10244 KB |
Output is correct |
9 |
Correct |
49 ms |
10176 KB |
Output is correct |
10 |
Correct |
48 ms |
10176 KB |
Output is correct |
11 |
Correct |
57 ms |
10320 KB |
Output is correct |
12 |
Correct |
49 ms |
10236 KB |
Output is correct |
13 |
Correct |
49 ms |
10236 KB |
Output is correct |
14 |
Correct |
68 ms |
10236 KB |
Output is correct |
15 |
Correct |
62 ms |
10316 KB |
Output is correct |
16 |
Correct |
56 ms |
10236 KB |
Output is correct |
17 |
Correct |
61 ms |
10324 KB |
Output is correct |
18 |
Correct |
56 ms |
10236 KB |
Output is correct |
19 |
Correct |
59 ms |
10236 KB |
Output is correct |
20 |
Correct |
2 ms |
592 KB |
Output is correct |
21 |
Correct |
2 ms |
592 KB |
Output is correct |
22 |
Correct |
2 ms |
592 KB |
Output is correct |
23 |
Correct |
2 ms |
592 KB |
Output is correct |
24 |
Correct |
2 ms |
428 KB |
Output is correct |
25 |
Correct |
2 ms |
760 KB |
Output is correct |
26 |
Correct |
59 ms |
10316 KB |
Output is correct |
27 |
Correct |
63 ms |
10280 KB |
Output is correct |
28 |
Correct |
65 ms |
10308 KB |
Output is correct |
29 |
Correct |
64 ms |
10304 KB |
Output is correct |
30 |
Correct |
66 ms |
10252 KB |
Output is correct |
31 |
Correct |
67 ms |
10336 KB |
Output is correct |
32 |
Execution timed out |
2068 ms |
11160 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |