# include "railroad.h"
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2;
long long dp[17][N];
int id[N];
vector <int> a, b;
bool cmp(int i, int j){
return b[i] <= a[j];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if(n <= 16){
for(int i = 1; i < N; i ++)
for(int j = 0; j < n; j ++)
dp[j][i] = 1e18;
for(int i = 0; i < n; i ++){
dp[i][1 << i] = 0;
}
for(int mask = 1; mask < (1 << n); mask ++){
for(int i = 0; i < n; i ++){
if(mask & (1 << i)) continue;
int to = mask + (1 << i);
for(int j = 0; j < n; j ++){
if(!(mask & (1 << j))) continue;
dp[i][to] = min(dp[i][to], dp[j][mask] + max(t[j] - s[i], 0));
}
}
}
long long ans = 1e18;
for(int i = 0; i < n; i ++)
ans = min(ans, dp[i][(1 << n) - 1]);
return ans;
} else {
a = s, b = t;
for(int i = 0; i < n; i ++)
id[i] = i;
sort(id, id + n, cmp);
bool ans = 0;
for(int i = 1; i < n; i ++)
if(s[id[i]] < t[id[i - 1]]) ans = 1;
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
n = 2 |
2 |
Correct |
5 ms |
3448 KB |
n = 2 |
3 |
Correct |
5 ms |
3620 KB |
n = 2 |
4 |
Correct |
5 ms |
3620 KB |
n = 2 |
5 |
Correct |
4 ms |
3668 KB |
n = 2 |
6 |
Correct |
5 ms |
3668 KB |
n = 2 |
7 |
Correct |
6 ms |
5280 KB |
n = 3 |
8 |
Correct |
6 ms |
5280 KB |
n = 3 |
9 |
Correct |
6 ms |
5328 KB |
n = 3 |
10 |
Correct |
13 ms |
13028 KB |
n = 8 |
11 |
Correct |
12 ms |
13028 KB |
n = 8 |
12 |
Correct |
12 ms |
13044 KB |
n = 8 |
13 |
Correct |
12 ms |
13044 KB |
n = 8 |
14 |
Correct |
14 ms |
13084 KB |
n = 8 |
15 |
Correct |
12 ms |
13084 KB |
n = 8 |
16 |
Correct |
12 ms |
13084 KB |
n = 8 |
17 |
Correct |
12 ms |
13084 KB |
n = 8 |
18 |
Correct |
12 ms |
13084 KB |
n = 8 |
19 |
Correct |
6 ms |
13084 KB |
n = 3 |
20 |
Correct |
11 ms |
13084 KB |
n = 7 |
21 |
Correct |
14 ms |
13100 KB |
n = 8 |
22 |
Correct |
14 ms |
13100 KB |
n = 8 |
23 |
Correct |
14 ms |
13100 KB |
n = 8 |
24 |
Correct |
14 ms |
13100 KB |
n = 8 |
25 |
Correct |
12 ms |
13100 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3448 KB |
n = 2 |
2 |
Correct |
5 ms |
3448 KB |
n = 2 |
3 |
Correct |
5 ms |
3620 KB |
n = 2 |
4 |
Correct |
5 ms |
3620 KB |
n = 2 |
5 |
Correct |
4 ms |
3668 KB |
n = 2 |
6 |
Correct |
5 ms |
3668 KB |
n = 2 |
7 |
Correct |
6 ms |
5280 KB |
n = 3 |
8 |
Correct |
6 ms |
5280 KB |
n = 3 |
9 |
Correct |
6 ms |
5328 KB |
n = 3 |
10 |
Correct |
13 ms |
13028 KB |
n = 8 |
11 |
Correct |
12 ms |
13028 KB |
n = 8 |
12 |
Correct |
12 ms |
13044 KB |
n = 8 |
13 |
Correct |
12 ms |
13044 KB |
n = 8 |
14 |
Correct |
14 ms |
13084 KB |
n = 8 |
15 |
Correct |
12 ms |
13084 KB |
n = 8 |
16 |
Correct |
12 ms |
13084 KB |
n = 8 |
17 |
Correct |
12 ms |
13084 KB |
n = 8 |
18 |
Correct |
12 ms |
13084 KB |
n = 8 |
19 |
Correct |
6 ms |
13084 KB |
n = 3 |
20 |
Correct |
11 ms |
13084 KB |
n = 7 |
21 |
Correct |
14 ms |
13100 KB |
n = 8 |
22 |
Correct |
14 ms |
13100 KB |
n = 8 |
23 |
Correct |
14 ms |
13100 KB |
n = 8 |
24 |
Correct |
14 ms |
13100 KB |
n = 8 |
25 |
Correct |
12 ms |
13100 KB |
n = 8 |
26 |
Correct |
14 ms |
13100 KB |
n = 8 |
27 |
Correct |
12 ms |
13100 KB |
n = 8 |
28 |
Correct |
11 ms |
13100 KB |
n = 8 |
29 |
Correct |
65 ms |
25580 KB |
n = 16 |
30 |
Correct |
59 ms |
25580 KB |
n = 16 |
31 |
Correct |
63 ms |
25712 KB |
n = 16 |
32 |
Correct |
60 ms |
25712 KB |
n = 16 |
33 |
Correct |
60 ms |
25712 KB |
n = 16 |
34 |
Correct |
62 ms |
25712 KB |
n = 16 |
35 |
Correct |
59 ms |
25712 KB |
n = 16 |
36 |
Correct |
38 ms |
25712 KB |
n = 15 |
37 |
Correct |
13 ms |
25712 KB |
n = 8 |
38 |
Correct |
61 ms |
25712 KB |
n = 16 |
39 |
Correct |
58 ms |
25780 KB |
n = 16 |
40 |
Correct |
15 ms |
25780 KB |
n = 9 |
41 |
Correct |
65 ms |
25780 KB |
n = 16 |
42 |
Correct |
60 ms |
25780 KB |
n = 16 |
43 |
Correct |
79 ms |
25780 KB |
n = 16 |
44 |
Correct |
16 ms |
25780 KB |
n = 9 |
45 |
Correct |
41 ms |
25780 KB |
n = 15 |
46 |
Correct |
60 ms |
25780 KB |
n = 16 |
47 |
Correct |
69 ms |
25780 KB |
n = 16 |
48 |
Correct |
56 ms |
25780 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
125 ms |
25780 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 |
5 ms |
3448 KB |
n = 2 |
2 |
Correct |
5 ms |
3448 KB |
n = 2 |
3 |
Correct |
5 ms |
3620 KB |
n = 2 |
4 |
Correct |
5 ms |
3620 KB |
n = 2 |
5 |
Correct |
4 ms |
3668 KB |
n = 2 |
6 |
Correct |
5 ms |
3668 KB |
n = 2 |
7 |
Correct |
6 ms |
5280 KB |
n = 3 |
8 |
Correct |
6 ms |
5280 KB |
n = 3 |
9 |
Correct |
6 ms |
5328 KB |
n = 3 |
10 |
Correct |
13 ms |
13028 KB |
n = 8 |
11 |
Correct |
12 ms |
13028 KB |
n = 8 |
12 |
Correct |
12 ms |
13044 KB |
n = 8 |
13 |
Correct |
12 ms |
13044 KB |
n = 8 |
14 |
Correct |
14 ms |
13084 KB |
n = 8 |
15 |
Correct |
12 ms |
13084 KB |
n = 8 |
16 |
Correct |
12 ms |
13084 KB |
n = 8 |
17 |
Correct |
12 ms |
13084 KB |
n = 8 |
18 |
Correct |
12 ms |
13084 KB |
n = 8 |
19 |
Correct |
6 ms |
13084 KB |
n = 3 |
20 |
Correct |
11 ms |
13084 KB |
n = 7 |
21 |
Correct |
14 ms |
13100 KB |
n = 8 |
22 |
Correct |
14 ms |
13100 KB |
n = 8 |
23 |
Correct |
14 ms |
13100 KB |
n = 8 |
24 |
Correct |
14 ms |
13100 KB |
n = 8 |
25 |
Correct |
12 ms |
13100 KB |
n = 8 |
26 |
Correct |
14 ms |
13100 KB |
n = 8 |
27 |
Correct |
12 ms |
13100 KB |
n = 8 |
28 |
Correct |
11 ms |
13100 KB |
n = 8 |
29 |
Correct |
65 ms |
25580 KB |
n = 16 |
30 |
Correct |
59 ms |
25580 KB |
n = 16 |
31 |
Correct |
63 ms |
25712 KB |
n = 16 |
32 |
Correct |
60 ms |
25712 KB |
n = 16 |
33 |
Correct |
60 ms |
25712 KB |
n = 16 |
34 |
Correct |
62 ms |
25712 KB |
n = 16 |
35 |
Correct |
59 ms |
25712 KB |
n = 16 |
36 |
Correct |
38 ms |
25712 KB |
n = 15 |
37 |
Correct |
13 ms |
25712 KB |
n = 8 |
38 |
Correct |
61 ms |
25712 KB |
n = 16 |
39 |
Correct |
58 ms |
25780 KB |
n = 16 |
40 |
Correct |
15 ms |
25780 KB |
n = 9 |
41 |
Correct |
65 ms |
25780 KB |
n = 16 |
42 |
Correct |
60 ms |
25780 KB |
n = 16 |
43 |
Correct |
79 ms |
25780 KB |
n = 16 |
44 |
Correct |
16 ms |
25780 KB |
n = 9 |
45 |
Correct |
41 ms |
25780 KB |
n = 15 |
46 |
Correct |
60 ms |
25780 KB |
n = 16 |
47 |
Correct |
69 ms |
25780 KB |
n = 16 |
48 |
Correct |
56 ms |
25780 KB |
n = 16 |
49 |
Runtime error |
125 ms |
25780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
50 |
Halted |
0 ms |
0 KB |
- |