#pragma once
#include <bits/stdc++.h>
#define MAX_N 16
#define INF 987654321987654321
using namespace std;
int N;
long long D[1<<MAX_N][MAX_N];
vector<long long> s, t;
void init(){
for(int i=0; i<N; ++i){
for(int j=0; j<(1<<N); ++j){
D[j][i]=-1;
}
}
for(int i=0; i<N; ++i){
D[1<<i][i]=0;
}
}
long long relu(long long v){
return v>0?v:0;
}
long long dp(int mask, int v){
//printf("mask=%d v=%d\n", mask, v);
if(D[mask][v]!=-1LL)return D[mask][v];
assert(mask&& (1<<v));
long long mini=INF;
for(int i=0; i<N; ++i){
if(((mask&(1<<i))!=0) && (i!=v)){
if(dp(mask^(1<<v), i)+relu(t[v]-s[i])<mini){
mini=dp(mask^(1<<v), i)+relu(t[v]-s[i]);
//printf("Pri (%d), mini=%lld\n", i, mini);
}
}
}
//printf("RET\n");
D[mask][v]=mini;
//printf("D[%d][%d]=%lld\n", mask, v, D[mask][v]);
return D[mask][v];
}
long long plan_roller_coaster(vector<int> S, vector<int> T) {
N=S.size();
for(int i=0; i<N; ++i){
s.push_back((long long)S[i]);
t.push_back((long long)T[i]);
}
init();
long long mini=INF;
for(int i=0; i<N; ++i){
if(dp((1<<N)-1, i)<mini){
mini=dp((1<<N)-1, i);
}
}
return mini;
}
Compilation message
railroad.cpp:1:9: warning: #pragma once in main file
#pragma once
^~~~
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from railroad.cpp:3:
railroad.cpp: In function 'long long int dp(int, int)':
railroad.cpp:30:18: warning: '<<' in boolean context, did you mean '<' ? [-Wint-in-bool-context]
assert(mask&& (1<<v));
~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
3 ms |
360 KB |
n = 2 |
3 |
Correct |
3 ms |
472 KB |
n = 2 |
4 |
Correct |
4 ms |
512 KB |
n = 2 |
5 |
Correct |
2 ms |
564 KB |
n = 2 |
6 |
Correct |
3 ms |
564 KB |
n = 2 |
7 |
Correct |
2 ms |
624 KB |
n = 3 |
8 |
Correct |
2 ms |
648 KB |
n = 3 |
9 |
Correct |
3 ms |
652 KB |
n = 3 |
10 |
Correct |
3 ms |
696 KB |
n = 8 |
11 |
Correct |
3 ms |
696 KB |
n = 8 |
12 |
Correct |
2 ms |
696 KB |
n = 8 |
13 |
Correct |
4 ms |
708 KB |
n = 8 |
14 |
Correct |
3 ms |
712 KB |
n = 8 |
15 |
Correct |
2 ms |
772 KB |
n = 8 |
16 |
Correct |
2 ms |
776 KB |
n = 8 |
17 |
Correct |
4 ms |
908 KB |
n = 8 |
18 |
Correct |
3 ms |
908 KB |
n = 8 |
19 |
Correct |
2 ms |
908 KB |
n = 3 |
20 |
Correct |
3 ms |
908 KB |
n = 7 |
21 |
Correct |
3 ms |
908 KB |
n = 8 |
22 |
Correct |
2 ms |
908 KB |
n = 8 |
23 |
Correct |
3 ms |
908 KB |
n = 8 |
24 |
Correct |
3 ms |
908 KB |
n = 8 |
25 |
Correct |
3 ms |
908 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
3 ms |
360 KB |
n = 2 |
3 |
Correct |
3 ms |
472 KB |
n = 2 |
4 |
Correct |
4 ms |
512 KB |
n = 2 |
5 |
Correct |
2 ms |
564 KB |
n = 2 |
6 |
Correct |
3 ms |
564 KB |
n = 2 |
7 |
Correct |
2 ms |
624 KB |
n = 3 |
8 |
Correct |
2 ms |
648 KB |
n = 3 |
9 |
Correct |
3 ms |
652 KB |
n = 3 |
10 |
Correct |
3 ms |
696 KB |
n = 8 |
11 |
Correct |
3 ms |
696 KB |
n = 8 |
12 |
Correct |
2 ms |
696 KB |
n = 8 |
13 |
Correct |
4 ms |
708 KB |
n = 8 |
14 |
Correct |
3 ms |
712 KB |
n = 8 |
15 |
Correct |
2 ms |
772 KB |
n = 8 |
16 |
Correct |
2 ms |
776 KB |
n = 8 |
17 |
Correct |
4 ms |
908 KB |
n = 8 |
18 |
Correct |
3 ms |
908 KB |
n = 8 |
19 |
Correct |
2 ms |
908 KB |
n = 3 |
20 |
Correct |
3 ms |
908 KB |
n = 7 |
21 |
Correct |
3 ms |
908 KB |
n = 8 |
22 |
Correct |
2 ms |
908 KB |
n = 8 |
23 |
Correct |
3 ms |
908 KB |
n = 8 |
24 |
Correct |
3 ms |
908 KB |
n = 8 |
25 |
Correct |
3 ms |
908 KB |
n = 8 |
26 |
Correct |
3 ms |
908 KB |
n = 8 |
27 |
Correct |
3 ms |
908 KB |
n = 8 |
28 |
Correct |
2 ms |
908 KB |
n = 8 |
29 |
Correct |
93 ms |
9004 KB |
n = 16 |
30 |
Correct |
109 ms |
9044 KB |
n = 16 |
31 |
Correct |
87 ms |
9048 KB |
n = 16 |
32 |
Correct |
106 ms |
9180 KB |
n = 16 |
33 |
Correct |
89 ms |
9200 KB |
n = 16 |
34 |
Correct |
88 ms |
9204 KB |
n = 16 |
35 |
Correct |
86 ms |
9204 KB |
n = 16 |
36 |
Correct |
44 ms |
9204 KB |
n = 15 |
37 |
Correct |
2 ms |
9204 KB |
n = 8 |
38 |
Correct |
97 ms |
9204 KB |
n = 16 |
39 |
Correct |
106 ms |
9208 KB |
n = 16 |
40 |
Correct |
3 ms |
9208 KB |
n = 9 |
41 |
Correct |
78 ms |
9208 KB |
n = 16 |
42 |
Correct |
99 ms |
9220 KB |
n = 16 |
43 |
Correct |
100 ms |
9220 KB |
n = 16 |
44 |
Correct |
2 ms |
9220 KB |
n = 9 |
45 |
Correct |
40 ms |
9220 KB |
n = 15 |
46 |
Correct |
105 ms |
9220 KB |
n = 16 |
47 |
Correct |
117 ms |
9220 KB |
n = 16 |
48 |
Correct |
85 ms |
9220 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
105 ms |
17924 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 |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
3 ms |
360 KB |
n = 2 |
3 |
Correct |
3 ms |
472 KB |
n = 2 |
4 |
Correct |
4 ms |
512 KB |
n = 2 |
5 |
Correct |
2 ms |
564 KB |
n = 2 |
6 |
Correct |
3 ms |
564 KB |
n = 2 |
7 |
Correct |
2 ms |
624 KB |
n = 3 |
8 |
Correct |
2 ms |
648 KB |
n = 3 |
9 |
Correct |
3 ms |
652 KB |
n = 3 |
10 |
Correct |
3 ms |
696 KB |
n = 8 |
11 |
Correct |
3 ms |
696 KB |
n = 8 |
12 |
Correct |
2 ms |
696 KB |
n = 8 |
13 |
Correct |
4 ms |
708 KB |
n = 8 |
14 |
Correct |
3 ms |
712 KB |
n = 8 |
15 |
Correct |
2 ms |
772 KB |
n = 8 |
16 |
Correct |
2 ms |
776 KB |
n = 8 |
17 |
Correct |
4 ms |
908 KB |
n = 8 |
18 |
Correct |
3 ms |
908 KB |
n = 8 |
19 |
Correct |
2 ms |
908 KB |
n = 3 |
20 |
Correct |
3 ms |
908 KB |
n = 7 |
21 |
Correct |
3 ms |
908 KB |
n = 8 |
22 |
Correct |
2 ms |
908 KB |
n = 8 |
23 |
Correct |
3 ms |
908 KB |
n = 8 |
24 |
Correct |
3 ms |
908 KB |
n = 8 |
25 |
Correct |
3 ms |
908 KB |
n = 8 |
26 |
Correct |
3 ms |
908 KB |
n = 8 |
27 |
Correct |
3 ms |
908 KB |
n = 8 |
28 |
Correct |
2 ms |
908 KB |
n = 8 |
29 |
Correct |
93 ms |
9004 KB |
n = 16 |
30 |
Correct |
109 ms |
9044 KB |
n = 16 |
31 |
Correct |
87 ms |
9048 KB |
n = 16 |
32 |
Correct |
106 ms |
9180 KB |
n = 16 |
33 |
Correct |
89 ms |
9200 KB |
n = 16 |
34 |
Correct |
88 ms |
9204 KB |
n = 16 |
35 |
Correct |
86 ms |
9204 KB |
n = 16 |
36 |
Correct |
44 ms |
9204 KB |
n = 15 |
37 |
Correct |
2 ms |
9204 KB |
n = 8 |
38 |
Correct |
97 ms |
9204 KB |
n = 16 |
39 |
Correct |
106 ms |
9208 KB |
n = 16 |
40 |
Correct |
3 ms |
9208 KB |
n = 9 |
41 |
Correct |
78 ms |
9208 KB |
n = 16 |
42 |
Correct |
99 ms |
9220 KB |
n = 16 |
43 |
Correct |
100 ms |
9220 KB |
n = 16 |
44 |
Correct |
2 ms |
9220 KB |
n = 9 |
45 |
Correct |
40 ms |
9220 KB |
n = 15 |
46 |
Correct |
105 ms |
9220 KB |
n = 16 |
47 |
Correct |
117 ms |
9220 KB |
n = 16 |
48 |
Correct |
85 ms |
9220 KB |
n = 16 |
49 |
Runtime error |
105 ms |
17924 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |