#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
long long memo[20][100000];
int n;
int arr1[20],arr2[20];
long long dp(int prev,int bm){
if (bm == (1<<n)-1) return 0;
if (memo[prev][bm] != -1) return memo[prev][bm];
memo[prev][bm] = 1e18;
for (int i = 0; i < n; i++){
if (bm & (1<<i)) continue;
int cost = max(0,arr2[prev]-arr1[i]);
memo[prev][bm] = min(memo[prev][bm],dp(i,bm+(1<<i))+cost);
}
return memo[prev][bm];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
n = (int) s.size();
if (n > 20) return 0;
for (int i = 0; i < n; i++){
arr1[i] = s[i];
arr2[i] = t[i];
}
for (int i = 0; i < 20; i++)for (int j = 0; j < 100000; j++) memo[i][j] = -1;
long long ans = 1e18;
for (int i = 0; i < n; i++) ans = min(ans,dp(i,1<<i));
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16000 KB |
n = 2 |
2 |
Correct |
15 ms |
16000 KB |
n = 2 |
3 |
Correct |
16 ms |
16000 KB |
n = 2 |
4 |
Correct |
16 ms |
16000 KB |
n = 2 |
5 |
Correct |
15 ms |
16000 KB |
n = 2 |
6 |
Correct |
15 ms |
16000 KB |
n = 2 |
7 |
Correct |
15 ms |
16000 KB |
n = 3 |
8 |
Correct |
14 ms |
16000 KB |
n = 3 |
9 |
Correct |
18 ms |
16000 KB |
n = 3 |
10 |
Correct |
18 ms |
16000 KB |
n = 8 |
11 |
Correct |
16 ms |
16000 KB |
n = 8 |
12 |
Correct |
18 ms |
16000 KB |
n = 8 |
13 |
Correct |
16 ms |
16000 KB |
n = 8 |
14 |
Correct |
15 ms |
16000 KB |
n = 8 |
15 |
Correct |
18 ms |
16000 KB |
n = 8 |
16 |
Correct |
17 ms |
16000 KB |
n = 8 |
17 |
Correct |
16 ms |
16000 KB |
n = 8 |
18 |
Correct |
16 ms |
16000 KB |
n = 8 |
19 |
Correct |
14 ms |
16000 KB |
n = 3 |
20 |
Correct |
15 ms |
16000 KB |
n = 7 |
21 |
Correct |
15 ms |
16000 KB |
n = 8 |
22 |
Correct |
16 ms |
16000 KB |
n = 8 |
23 |
Correct |
16 ms |
16000 KB |
n = 8 |
24 |
Correct |
18 ms |
16000 KB |
n = 8 |
25 |
Correct |
19 ms |
16000 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16000 KB |
n = 2 |
2 |
Correct |
15 ms |
16000 KB |
n = 2 |
3 |
Correct |
16 ms |
16000 KB |
n = 2 |
4 |
Correct |
16 ms |
16000 KB |
n = 2 |
5 |
Correct |
15 ms |
16000 KB |
n = 2 |
6 |
Correct |
15 ms |
16000 KB |
n = 2 |
7 |
Correct |
15 ms |
16000 KB |
n = 3 |
8 |
Correct |
14 ms |
16000 KB |
n = 3 |
9 |
Correct |
18 ms |
16000 KB |
n = 3 |
10 |
Correct |
18 ms |
16000 KB |
n = 8 |
11 |
Correct |
16 ms |
16000 KB |
n = 8 |
12 |
Correct |
18 ms |
16000 KB |
n = 8 |
13 |
Correct |
16 ms |
16000 KB |
n = 8 |
14 |
Correct |
15 ms |
16000 KB |
n = 8 |
15 |
Correct |
18 ms |
16000 KB |
n = 8 |
16 |
Correct |
17 ms |
16000 KB |
n = 8 |
17 |
Correct |
16 ms |
16000 KB |
n = 8 |
18 |
Correct |
16 ms |
16000 KB |
n = 8 |
19 |
Correct |
14 ms |
16000 KB |
n = 3 |
20 |
Correct |
15 ms |
16000 KB |
n = 7 |
21 |
Correct |
15 ms |
16000 KB |
n = 8 |
22 |
Correct |
16 ms |
16000 KB |
n = 8 |
23 |
Correct |
16 ms |
16000 KB |
n = 8 |
24 |
Correct |
18 ms |
16000 KB |
n = 8 |
25 |
Correct |
19 ms |
16000 KB |
n = 8 |
26 |
Correct |
18 ms |
16000 KB |
n = 8 |
27 |
Correct |
16 ms |
16128 KB |
n = 8 |
28 |
Correct |
16 ms |
16000 KB |
n = 8 |
29 |
Correct |
135 ms |
16092 KB |
n = 16 |
30 |
Correct |
161 ms |
16016 KB |
n = 16 |
31 |
Correct |
166 ms |
16000 KB |
n = 16 |
32 |
Correct |
166 ms |
16000 KB |
n = 16 |
33 |
Correct |
152 ms |
16000 KB |
n = 16 |
34 |
Correct |
162 ms |
16000 KB |
n = 16 |
35 |
Correct |
143 ms |
16000 KB |
n = 16 |
36 |
Correct |
49 ms |
16000 KB |
n = 15 |
37 |
Correct |
15 ms |
16000 KB |
n = 8 |
38 |
Correct |
159 ms |
15992 KB |
n = 16 |
39 |
Correct |
115 ms |
16024 KB |
n = 16 |
40 |
Correct |
15 ms |
16000 KB |
n = 9 |
41 |
Correct |
116 ms |
16000 KB |
n = 16 |
42 |
Correct |
111 ms |
16000 KB |
n = 16 |
43 |
Correct |
130 ms |
16000 KB |
n = 16 |
44 |
Correct |
19 ms |
16000 KB |
n = 9 |
45 |
Correct |
72 ms |
16120 KB |
n = 15 |
46 |
Correct |
127 ms |
16000 KB |
n = 16 |
47 |
Correct |
164 ms |
16120 KB |
n = 16 |
48 |
Correct |
148 ms |
16044 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
7288 KB |
n = 199999 |
2 |
Incorrect |
80 ms |
7288 KB |
answer is not correct: 0 instead of 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
16000 KB |
n = 2 |
2 |
Correct |
15 ms |
16000 KB |
n = 2 |
3 |
Correct |
16 ms |
16000 KB |
n = 2 |
4 |
Correct |
16 ms |
16000 KB |
n = 2 |
5 |
Correct |
15 ms |
16000 KB |
n = 2 |
6 |
Correct |
15 ms |
16000 KB |
n = 2 |
7 |
Correct |
15 ms |
16000 KB |
n = 3 |
8 |
Correct |
14 ms |
16000 KB |
n = 3 |
9 |
Correct |
18 ms |
16000 KB |
n = 3 |
10 |
Correct |
18 ms |
16000 KB |
n = 8 |
11 |
Correct |
16 ms |
16000 KB |
n = 8 |
12 |
Correct |
18 ms |
16000 KB |
n = 8 |
13 |
Correct |
16 ms |
16000 KB |
n = 8 |
14 |
Correct |
15 ms |
16000 KB |
n = 8 |
15 |
Correct |
18 ms |
16000 KB |
n = 8 |
16 |
Correct |
17 ms |
16000 KB |
n = 8 |
17 |
Correct |
16 ms |
16000 KB |
n = 8 |
18 |
Correct |
16 ms |
16000 KB |
n = 8 |
19 |
Correct |
14 ms |
16000 KB |
n = 3 |
20 |
Correct |
15 ms |
16000 KB |
n = 7 |
21 |
Correct |
15 ms |
16000 KB |
n = 8 |
22 |
Correct |
16 ms |
16000 KB |
n = 8 |
23 |
Correct |
16 ms |
16000 KB |
n = 8 |
24 |
Correct |
18 ms |
16000 KB |
n = 8 |
25 |
Correct |
19 ms |
16000 KB |
n = 8 |
26 |
Correct |
18 ms |
16000 KB |
n = 8 |
27 |
Correct |
16 ms |
16128 KB |
n = 8 |
28 |
Correct |
16 ms |
16000 KB |
n = 8 |
29 |
Correct |
135 ms |
16092 KB |
n = 16 |
30 |
Correct |
161 ms |
16016 KB |
n = 16 |
31 |
Correct |
166 ms |
16000 KB |
n = 16 |
32 |
Correct |
166 ms |
16000 KB |
n = 16 |
33 |
Correct |
152 ms |
16000 KB |
n = 16 |
34 |
Correct |
162 ms |
16000 KB |
n = 16 |
35 |
Correct |
143 ms |
16000 KB |
n = 16 |
36 |
Correct |
49 ms |
16000 KB |
n = 15 |
37 |
Correct |
15 ms |
16000 KB |
n = 8 |
38 |
Correct |
159 ms |
15992 KB |
n = 16 |
39 |
Correct |
115 ms |
16024 KB |
n = 16 |
40 |
Correct |
15 ms |
16000 KB |
n = 9 |
41 |
Correct |
116 ms |
16000 KB |
n = 16 |
42 |
Correct |
111 ms |
16000 KB |
n = 16 |
43 |
Correct |
130 ms |
16000 KB |
n = 16 |
44 |
Correct |
19 ms |
16000 KB |
n = 9 |
45 |
Correct |
72 ms |
16120 KB |
n = 15 |
46 |
Correct |
127 ms |
16000 KB |
n = 16 |
47 |
Correct |
164 ms |
16120 KB |
n = 16 |
48 |
Correct |
148 ms |
16044 KB |
n = 16 |
49 |
Correct |
85 ms |
7288 KB |
n = 199999 |
50 |
Incorrect |
80 ms |
7288 KB |
answer is not correct: 0 instead of 1 |
51 |
Halted |
0 ms |
0 KB |
- |