#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> s_;
vector<int> t_;
long long mem[17][65537];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
/*if (n<=8){
vector<int> v;
for (int x = 0; x<n; x++){
v.push_back(x);
}
long long ans = 999999999999999;
long long curans = 0;
for (int x = 1; x<n; x++){
curans+=(t[x-1]>s[x])?(t[x-1]-s[x]):0;
}
ans = min(curans,ans);
while (next_permutation(v.begin(),v.end())){
long long curans = 0;
for (int x = 1; x<n; x++){
curans+=(t[v[x-1]]>s[v[x]])?(t[v[x-1]]-s[v[x]]):0;
}
ans = min(curans,ans);
}
return ans;
}
else{*/
memset(mem,-1,sizeof(mem));
for (int x = 0; x<n; x++){
s_.push_back(s[x]);
t_.push_back(t[x]);
}
long long fans = 999999999999999;
for (int bitmask = 0; bitmask<(1<<n); bitmask++){
for (int cur = 0; cur<n; cur++){
if (bitmask==0) {mem[cur][bitmask]=0;continue;}
int cop = bitmask;
long long ans = 999999999999999;
for (int x = 0;cop!=0 ; x++){
if ((cop&(1<<x))!=0){
ans = min(ans,mem[x][bitmask-(1<<x)]+((t_[cur]>s_[x])?(t_[cur]-s_[x]):0));
cop-=(1<<x);
}
//printf("%i\n",x);
}
mem[cur][bitmask] = ans;
}
}
for (int x = 0; x<n; x++){
fans = min(fans,mem[x][(1<<n)-1-(1<<x)]);
}
return fans;
//}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9088 KB |
n = 2 |
2 |
Correct |
10 ms |
9088 KB |
n = 2 |
3 |
Correct |
7 ms |
9088 KB |
n = 2 |
4 |
Correct |
9 ms |
9060 KB |
n = 2 |
5 |
Correct |
10 ms |
9088 KB |
n = 2 |
6 |
Correct |
9 ms |
9088 KB |
n = 2 |
7 |
Correct |
11 ms |
9060 KB |
n = 3 |
8 |
Correct |
11 ms |
9088 KB |
n = 3 |
9 |
Correct |
10 ms |
9088 KB |
n = 3 |
10 |
Correct |
11 ms |
9216 KB |
n = 8 |
11 |
Correct |
10 ms |
9088 KB |
n = 8 |
12 |
Correct |
9 ms |
9088 KB |
n = 8 |
13 |
Correct |
9 ms |
9008 KB |
n = 8 |
14 |
Correct |
10 ms |
9088 KB |
n = 8 |
15 |
Correct |
10 ms |
9060 KB |
n = 8 |
16 |
Correct |
11 ms |
9088 KB |
n = 8 |
17 |
Correct |
9 ms |
9088 KB |
n = 8 |
18 |
Correct |
11 ms |
9088 KB |
n = 8 |
19 |
Correct |
8 ms |
8960 KB |
n = 3 |
20 |
Correct |
10 ms |
9088 KB |
n = 7 |
21 |
Correct |
9 ms |
9084 KB |
n = 8 |
22 |
Correct |
12 ms |
9088 KB |
n = 8 |
23 |
Correct |
11 ms |
9088 KB |
n = 8 |
24 |
Correct |
10 ms |
9088 KB |
n = 8 |
25 |
Correct |
10 ms |
9088 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9088 KB |
n = 2 |
2 |
Correct |
10 ms |
9088 KB |
n = 2 |
3 |
Correct |
7 ms |
9088 KB |
n = 2 |
4 |
Correct |
9 ms |
9060 KB |
n = 2 |
5 |
Correct |
10 ms |
9088 KB |
n = 2 |
6 |
Correct |
9 ms |
9088 KB |
n = 2 |
7 |
Correct |
11 ms |
9060 KB |
n = 3 |
8 |
Correct |
11 ms |
9088 KB |
n = 3 |
9 |
Correct |
10 ms |
9088 KB |
n = 3 |
10 |
Correct |
11 ms |
9216 KB |
n = 8 |
11 |
Correct |
10 ms |
9088 KB |
n = 8 |
12 |
Correct |
9 ms |
9088 KB |
n = 8 |
13 |
Correct |
9 ms |
9008 KB |
n = 8 |
14 |
Correct |
10 ms |
9088 KB |
n = 8 |
15 |
Correct |
10 ms |
9060 KB |
n = 8 |
16 |
Correct |
11 ms |
9088 KB |
n = 8 |
17 |
Correct |
9 ms |
9088 KB |
n = 8 |
18 |
Correct |
11 ms |
9088 KB |
n = 8 |
19 |
Correct |
8 ms |
8960 KB |
n = 3 |
20 |
Correct |
10 ms |
9088 KB |
n = 7 |
21 |
Correct |
9 ms |
9084 KB |
n = 8 |
22 |
Correct |
12 ms |
9088 KB |
n = 8 |
23 |
Correct |
11 ms |
9088 KB |
n = 8 |
24 |
Correct |
10 ms |
9088 KB |
n = 8 |
25 |
Correct |
10 ms |
9088 KB |
n = 8 |
26 |
Correct |
12 ms |
9088 KB |
n = 8 |
27 |
Correct |
10 ms |
9088 KB |
n = 8 |
28 |
Correct |
9 ms |
9088 KB |
n = 8 |
29 |
Correct |
65 ms |
9088 KB |
n = 16 |
30 |
Correct |
73 ms |
9208 KB |
n = 16 |
31 |
Correct |
67 ms |
9080 KB |
n = 16 |
32 |
Correct |
64 ms |
9208 KB |
n = 16 |
33 |
Correct |
42 ms |
9076 KB |
n = 16 |
34 |
Correct |
71 ms |
9080 KB |
n = 16 |
35 |
Correct |
80 ms |
9208 KB |
n = 16 |
36 |
Correct |
47 ms |
9084 KB |
n = 15 |
37 |
Correct |
9 ms |
8960 KB |
n = 8 |
38 |
Correct |
81 ms |
9088 KB |
n = 16 |
39 |
Correct |
87 ms |
9080 KB |
n = 16 |
40 |
Correct |
10 ms |
9020 KB |
n = 9 |
41 |
Correct |
51 ms |
9080 KB |
n = 16 |
42 |
Correct |
68 ms |
9212 KB |
n = 16 |
43 |
Correct |
44 ms |
9088 KB |
n = 16 |
44 |
Correct |
9 ms |
9088 KB |
n = 9 |
45 |
Correct |
41 ms |
9088 KB |
n = 15 |
46 |
Correct |
79 ms |
9080 KB |
n = 16 |
47 |
Correct |
76 ms |
9080 KB |
n = 16 |
48 |
Correct |
76 ms |
9088 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
108 ms |
27728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9088 KB |
n = 2 |
2 |
Correct |
10 ms |
9088 KB |
n = 2 |
3 |
Correct |
7 ms |
9088 KB |
n = 2 |
4 |
Correct |
9 ms |
9060 KB |
n = 2 |
5 |
Correct |
10 ms |
9088 KB |
n = 2 |
6 |
Correct |
9 ms |
9088 KB |
n = 2 |
7 |
Correct |
11 ms |
9060 KB |
n = 3 |
8 |
Correct |
11 ms |
9088 KB |
n = 3 |
9 |
Correct |
10 ms |
9088 KB |
n = 3 |
10 |
Correct |
11 ms |
9216 KB |
n = 8 |
11 |
Correct |
10 ms |
9088 KB |
n = 8 |
12 |
Correct |
9 ms |
9088 KB |
n = 8 |
13 |
Correct |
9 ms |
9008 KB |
n = 8 |
14 |
Correct |
10 ms |
9088 KB |
n = 8 |
15 |
Correct |
10 ms |
9060 KB |
n = 8 |
16 |
Correct |
11 ms |
9088 KB |
n = 8 |
17 |
Correct |
9 ms |
9088 KB |
n = 8 |
18 |
Correct |
11 ms |
9088 KB |
n = 8 |
19 |
Correct |
8 ms |
8960 KB |
n = 3 |
20 |
Correct |
10 ms |
9088 KB |
n = 7 |
21 |
Correct |
9 ms |
9084 KB |
n = 8 |
22 |
Correct |
12 ms |
9088 KB |
n = 8 |
23 |
Correct |
11 ms |
9088 KB |
n = 8 |
24 |
Correct |
10 ms |
9088 KB |
n = 8 |
25 |
Correct |
10 ms |
9088 KB |
n = 8 |
26 |
Correct |
12 ms |
9088 KB |
n = 8 |
27 |
Correct |
10 ms |
9088 KB |
n = 8 |
28 |
Correct |
9 ms |
9088 KB |
n = 8 |
29 |
Correct |
65 ms |
9088 KB |
n = 16 |
30 |
Correct |
73 ms |
9208 KB |
n = 16 |
31 |
Correct |
67 ms |
9080 KB |
n = 16 |
32 |
Correct |
64 ms |
9208 KB |
n = 16 |
33 |
Correct |
42 ms |
9076 KB |
n = 16 |
34 |
Correct |
71 ms |
9080 KB |
n = 16 |
35 |
Correct |
80 ms |
9208 KB |
n = 16 |
36 |
Correct |
47 ms |
9084 KB |
n = 15 |
37 |
Correct |
9 ms |
8960 KB |
n = 8 |
38 |
Correct |
81 ms |
9088 KB |
n = 16 |
39 |
Correct |
87 ms |
9080 KB |
n = 16 |
40 |
Correct |
10 ms |
9020 KB |
n = 9 |
41 |
Correct |
51 ms |
9080 KB |
n = 16 |
42 |
Correct |
68 ms |
9212 KB |
n = 16 |
43 |
Correct |
44 ms |
9088 KB |
n = 16 |
44 |
Correct |
9 ms |
9088 KB |
n = 9 |
45 |
Correct |
41 ms |
9088 KB |
n = 15 |
46 |
Correct |
79 ms |
9080 KB |
n = 16 |
47 |
Correct |
76 ms |
9080 KB |
n = 16 |
48 |
Correct |
76 ms |
9088 KB |
n = 16 |
49 |
Runtime error |
108 ms |
27728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |