#include "railroad.h"
#include <bits/stdc++.h>
using namespace std ;
const int N = 16 ;
const long long oo = 1e15 ;
long long dp [(1<<N)][N+1] ;
int mk = 0 ;
int n = 0 ;
int S[N+2], T[N+2] ;
long long go ( int mask, int lst ) {
if ( mk == mask ) return 0 ;
auto &rf = dp[mask][lst] ;
if ( rf!=-1 ) return rf;
rf = oo ;
for ( int j = 0 ; j < n ; ++j ) {
if ( mask & (1<<j) ) continue ;
int v = 0 ;
if ( mask ) v = max ( 0, T[lst] - S[j]) ;
rf = min ( rf, go (mask | (1<<j), j) + v ) ;
}
return rf ;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
n = (int) s.size();
mk = (1<<n)-1 ;
for ( int i = 0 ; i < n ; ++i ) S[i] = s[i], T[i] = t[i] ;
memset ( dp, -1, sizeof dp ) ;
return go ( 0, 0 );
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9088 KB |
n = 2 |
2 |
Correct |
5 ms |
9088 KB |
n = 2 |
3 |
Correct |
5 ms |
9088 KB |
n = 2 |
4 |
Correct |
7 ms |
9088 KB |
n = 2 |
5 |
Correct |
5 ms |
9088 KB |
n = 2 |
6 |
Correct |
5 ms |
9088 KB |
n = 2 |
7 |
Correct |
5 ms |
9216 KB |
n = 3 |
8 |
Correct |
5 ms |
9088 KB |
n = 3 |
9 |
Correct |
5 ms |
9088 KB |
n = 3 |
10 |
Correct |
6 ms |
9088 KB |
n = 8 |
11 |
Correct |
6 ms |
9088 KB |
n = 8 |
12 |
Correct |
6 ms |
9088 KB |
n = 8 |
13 |
Correct |
5 ms |
9088 KB |
n = 8 |
14 |
Correct |
6 ms |
9088 KB |
n = 8 |
15 |
Correct |
6 ms |
9088 KB |
n = 8 |
16 |
Correct |
6 ms |
9088 KB |
n = 8 |
17 |
Correct |
5 ms |
9088 KB |
n = 8 |
18 |
Correct |
5 ms |
9088 KB |
n = 8 |
19 |
Correct |
5 ms |
9088 KB |
n = 3 |
20 |
Correct |
5 ms |
9088 KB |
n = 7 |
21 |
Correct |
6 ms |
9088 KB |
n = 8 |
22 |
Correct |
6 ms |
9088 KB |
n = 8 |
23 |
Correct |
5 ms |
9088 KB |
n = 8 |
24 |
Correct |
6 ms |
9088 KB |
n = 8 |
25 |
Correct |
6 ms |
9088 KB |
n = 8 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9088 KB |
n = 2 |
2 |
Correct |
5 ms |
9088 KB |
n = 2 |
3 |
Correct |
5 ms |
9088 KB |
n = 2 |
4 |
Correct |
7 ms |
9088 KB |
n = 2 |
5 |
Correct |
5 ms |
9088 KB |
n = 2 |
6 |
Correct |
5 ms |
9088 KB |
n = 2 |
7 |
Correct |
5 ms |
9216 KB |
n = 3 |
8 |
Correct |
5 ms |
9088 KB |
n = 3 |
9 |
Correct |
5 ms |
9088 KB |
n = 3 |
10 |
Correct |
6 ms |
9088 KB |
n = 8 |
11 |
Correct |
6 ms |
9088 KB |
n = 8 |
12 |
Correct |
6 ms |
9088 KB |
n = 8 |
13 |
Correct |
5 ms |
9088 KB |
n = 8 |
14 |
Correct |
6 ms |
9088 KB |
n = 8 |
15 |
Correct |
6 ms |
9088 KB |
n = 8 |
16 |
Correct |
6 ms |
9088 KB |
n = 8 |
17 |
Correct |
5 ms |
9088 KB |
n = 8 |
18 |
Correct |
5 ms |
9088 KB |
n = 8 |
19 |
Correct |
5 ms |
9088 KB |
n = 3 |
20 |
Correct |
5 ms |
9088 KB |
n = 7 |
21 |
Correct |
6 ms |
9088 KB |
n = 8 |
22 |
Correct |
6 ms |
9088 KB |
n = 8 |
23 |
Correct |
5 ms |
9088 KB |
n = 8 |
24 |
Correct |
6 ms |
9088 KB |
n = 8 |
25 |
Correct |
6 ms |
9088 KB |
n = 8 |
26 |
Correct |
5 ms |
9088 KB |
n = 8 |
27 |
Correct |
6 ms |
9088 KB |
n = 8 |
28 |
Correct |
6 ms |
9216 KB |
n = 8 |
29 |
Correct |
85 ms |
9208 KB |
n = 16 |
30 |
Correct |
77 ms |
9088 KB |
n = 16 |
31 |
Correct |
79 ms |
9088 KB |
n = 16 |
32 |
Correct |
78 ms |
9088 KB |
n = 16 |
33 |
Correct |
79 ms |
9088 KB |
n = 16 |
34 |
Correct |
79 ms |
9088 KB |
n = 16 |
35 |
Correct |
80 ms |
9088 KB |
n = 16 |
36 |
Correct |
34 ms |
9088 KB |
n = 15 |
37 |
Correct |
6 ms |
9088 KB |
n = 8 |
38 |
Correct |
80 ms |
9216 KB |
n = 16 |
39 |
Correct |
79 ms |
9088 KB |
n = 16 |
40 |
Correct |
6 ms |
9088 KB |
n = 9 |
41 |
Correct |
80 ms |
9088 KB |
n = 16 |
42 |
Correct |
79 ms |
9088 KB |
n = 16 |
43 |
Correct |
81 ms |
9088 KB |
n = 16 |
44 |
Correct |
6 ms |
9088 KB |
n = 9 |
45 |
Correct |
35 ms |
9088 KB |
n = 15 |
46 |
Correct |
77 ms |
9088 KB |
n = 16 |
47 |
Correct |
81 ms |
9216 KB |
n = 16 |
48 |
Correct |
79 ms |
9088 KB |
n = 16 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
94 ms |
24824 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9088 KB |
n = 2 |
2 |
Correct |
5 ms |
9088 KB |
n = 2 |
3 |
Correct |
5 ms |
9088 KB |
n = 2 |
4 |
Correct |
7 ms |
9088 KB |
n = 2 |
5 |
Correct |
5 ms |
9088 KB |
n = 2 |
6 |
Correct |
5 ms |
9088 KB |
n = 2 |
7 |
Correct |
5 ms |
9216 KB |
n = 3 |
8 |
Correct |
5 ms |
9088 KB |
n = 3 |
9 |
Correct |
5 ms |
9088 KB |
n = 3 |
10 |
Correct |
6 ms |
9088 KB |
n = 8 |
11 |
Correct |
6 ms |
9088 KB |
n = 8 |
12 |
Correct |
6 ms |
9088 KB |
n = 8 |
13 |
Correct |
5 ms |
9088 KB |
n = 8 |
14 |
Correct |
6 ms |
9088 KB |
n = 8 |
15 |
Correct |
6 ms |
9088 KB |
n = 8 |
16 |
Correct |
6 ms |
9088 KB |
n = 8 |
17 |
Correct |
5 ms |
9088 KB |
n = 8 |
18 |
Correct |
5 ms |
9088 KB |
n = 8 |
19 |
Correct |
5 ms |
9088 KB |
n = 3 |
20 |
Correct |
5 ms |
9088 KB |
n = 7 |
21 |
Correct |
6 ms |
9088 KB |
n = 8 |
22 |
Correct |
6 ms |
9088 KB |
n = 8 |
23 |
Correct |
5 ms |
9088 KB |
n = 8 |
24 |
Correct |
6 ms |
9088 KB |
n = 8 |
25 |
Correct |
6 ms |
9088 KB |
n = 8 |
26 |
Correct |
5 ms |
9088 KB |
n = 8 |
27 |
Correct |
6 ms |
9088 KB |
n = 8 |
28 |
Correct |
6 ms |
9216 KB |
n = 8 |
29 |
Correct |
85 ms |
9208 KB |
n = 16 |
30 |
Correct |
77 ms |
9088 KB |
n = 16 |
31 |
Correct |
79 ms |
9088 KB |
n = 16 |
32 |
Correct |
78 ms |
9088 KB |
n = 16 |
33 |
Correct |
79 ms |
9088 KB |
n = 16 |
34 |
Correct |
79 ms |
9088 KB |
n = 16 |
35 |
Correct |
80 ms |
9088 KB |
n = 16 |
36 |
Correct |
34 ms |
9088 KB |
n = 15 |
37 |
Correct |
6 ms |
9088 KB |
n = 8 |
38 |
Correct |
80 ms |
9216 KB |
n = 16 |
39 |
Correct |
79 ms |
9088 KB |
n = 16 |
40 |
Correct |
6 ms |
9088 KB |
n = 9 |
41 |
Correct |
80 ms |
9088 KB |
n = 16 |
42 |
Correct |
79 ms |
9088 KB |
n = 16 |
43 |
Correct |
81 ms |
9088 KB |
n = 16 |
44 |
Correct |
6 ms |
9088 KB |
n = 9 |
45 |
Correct |
35 ms |
9088 KB |
n = 15 |
46 |
Correct |
77 ms |
9088 KB |
n = 16 |
47 |
Correct |
81 ms |
9216 KB |
n = 16 |
48 |
Correct |
79 ms |
9088 KB |
n = 16 |
49 |
Runtime error |
94 ms |
24824 KB |
Execution killed with signal 11 |
50 |
Halted |
0 ms |
0 KB |
- |