#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
//#include "nile.h"
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(2e5)+7;
int n , q;
ll dp[maxN];
vector<int> w , a , b , e , id;
vector<ll> res;
namespace sub1{
bool check(){
return (q <= 5 && n <= 2000);
}
void solve(){
for (int d : e){
dp[0] = 0;
for (int i = 0 ; i < n ; i++){
ll s = 0;
int x = INT_MAX;
dp[i + 1] = ll(1e18);
for (int j = i ; j >= 0 ; j--){
s += b[id[j]];
x = min(x , a[id[j]] - b[id[j]]);
if (w[id[i]] - w[id[j]] <= d){
if ((i - j)&1){
dp[i + 1] = min(dp[i + 1] , dp[j] + s);
}
else{
dp[i + 1] = min(dp[i + 1] , dp[j] + s + 1ll * x);
}
}
else{
break;
}
}
}
res.push_back(dp[n]);
}
}
}
namespace sub2{
bool check(){
return (q <= 5);
}
void solve(){
for (int d : e){
dp[0] = 0;
for (int i = 0 ; i < n ; i++){
dp[i + 1] = dp[i] + 1ll * a[id[i]];
if (i - 1 >= 0 && w[id[i]] - w[id[i - 1]] <= d){
dp[i + 1] = min(dp[i + 1] , dp[i - 1] + 1ll * b[id[i]] + 1ll * b[id[i - 1]]);
}
if (i - 2 >= 0 && w[id[i]] - w[id[i - 2]] <= d){
dp[i + 1] = min(dp[i + 1] , dp[i - 2] + 1ll * b[id[i]] + 1ll * a[id[i - 1]] + 1ll * b[id[i - 2]]);
}
}
res.push_back(dp[n]);
}
}
}
vector<long long> calculate_costs(vector<int> _w , vector<int> _a , vector<int> _b , vector<int> _e){
w = _w; a = _a; b = _b; e = _e;
n = sz(w) , q = sz(e);
id.resize(n);
for (int i = 0 ; i < n ; i++) id[i] = i;
sort(all(id) , [](int x , int y){
return w[x] < w[y];
});
if (sub2::check()){
sub2::solve();
return res;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4944 KB |
Output is correct |
2 |
Correct |
28 ms |
4944 KB |
Output is correct |
3 |
Correct |
24 ms |
4992 KB |
Output is correct |
4 |
Correct |
25 ms |
4944 KB |
Output is correct |
5 |
Correct |
25 ms |
4936 KB |
Output is correct |
6 |
Correct |
24 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4944 KB |
Output is correct |
2 |
Correct |
30 ms |
4940 KB |
Output is correct |
3 |
Correct |
30 ms |
4956 KB |
Output is correct |
4 |
Correct |
30 ms |
4952 KB |
Output is correct |
5 |
Correct |
29 ms |
4944 KB |
Output is correct |
6 |
Correct |
29 ms |
4968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
24 ms |
4944 KB |
Output is correct |
8 |
Correct |
28 ms |
4944 KB |
Output is correct |
9 |
Correct |
24 ms |
4992 KB |
Output is correct |
10 |
Correct |
25 ms |
4944 KB |
Output is correct |
11 |
Correct |
25 ms |
4936 KB |
Output is correct |
12 |
Correct |
24 ms |
4940 KB |
Output is correct |
13 |
Correct |
29 ms |
4944 KB |
Output is correct |
14 |
Correct |
30 ms |
4940 KB |
Output is correct |
15 |
Correct |
30 ms |
4956 KB |
Output is correct |
16 |
Correct |
30 ms |
4952 KB |
Output is correct |
17 |
Correct |
29 ms |
4944 KB |
Output is correct |
18 |
Correct |
29 ms |
4968 KB |
Output is correct |
19 |
Correct |
2 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
33 ms |
4936 KB |
Output is correct |
26 |
Correct |
52 ms |
4944 KB |
Output is correct |
27 |
Correct |
37 ms |
5128 KB |
Output is correct |
28 |
Correct |
35 ms |
4944 KB |
Output is correct |
29 |
Correct |
38 ms |
4944 KB |
Output is correct |
30 |
Correct |
35 ms |
5128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
4944 KB |
Output is correct |
2 |
Correct |
30 ms |
4940 KB |
Output is correct |
3 |
Correct |
30 ms |
4956 KB |
Output is correct |
4 |
Correct |
30 ms |
4952 KB |
Output is correct |
5 |
Correct |
29 ms |
4944 KB |
Output is correct |
6 |
Correct |
29 ms |
4968 KB |
Output is correct |
7 |
Incorrect |
30 ms |
5456 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
24 ms |
4944 KB |
Output is correct |
9 |
Correct |
28 ms |
4944 KB |
Output is correct |
10 |
Correct |
24 ms |
4992 KB |
Output is correct |
11 |
Correct |
25 ms |
4944 KB |
Output is correct |
12 |
Correct |
25 ms |
4936 KB |
Output is correct |
13 |
Correct |
24 ms |
4940 KB |
Output is correct |
14 |
Correct |
29 ms |
4944 KB |
Output is correct |
15 |
Correct |
30 ms |
4940 KB |
Output is correct |
16 |
Correct |
30 ms |
4956 KB |
Output is correct |
17 |
Correct |
30 ms |
4952 KB |
Output is correct |
18 |
Correct |
29 ms |
4944 KB |
Output is correct |
19 |
Correct |
29 ms |
4968 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
33 ms |
4936 KB |
Output is correct |
27 |
Correct |
52 ms |
4944 KB |
Output is correct |
28 |
Correct |
37 ms |
5128 KB |
Output is correct |
29 |
Correct |
35 ms |
4944 KB |
Output is correct |
30 |
Correct |
38 ms |
4944 KB |
Output is correct |
31 |
Correct |
35 ms |
5128 KB |
Output is correct |
32 |
Incorrect |
30 ms |
5456 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |