#include "railroad.h"
#include <bits/stdc++.h>
#define long long long
#define pii pair<long, long>
#define x first
#define y second
using namespace std;
const int N = 16;
int n;
vector<int> s, t;
long dp[N][1<<N];
long solve(int u, int bit) {
if(dp[u][bit] != -1) return dp[u][bit];
if((bit ^ (1 << u)) == 0) return dp[u][bit] = 0;
dp[u][bit] = 1e18;
for(int i = 0; i < n; ++i) if(i != u && ((bit >> i) & 1)) {
long val = (t[i] > s[u] ? (t[i] - s[u]) : 0) + solve(i, bit ^ (1 << u));
dp[u][bit] = min(dp[u][bit], val);
}
return dp[u][bit];
}
long s1() {
memset(dp, -1, sizeof dp);
int bit = (1 << n) - 1;
long ans = 1e18;
for(int i = 0; i < n; ++i) ans = min(ans, solve(i, bit));
return ans;
}
long s2() {
vector<pii> vec;
for(int i = 0; i < n; ++i) vec.emplace_back(s[i], t[i]);
sort(vec.begin(), vec.end(), [&](const pii &a, const pii &b) { return a.y == b.y ? a.x < b.x : a.y < b.y; });
for(int i = 1; i < n; ++i) if(vec[i-1].y > vec[i].x) return 1;
return 0;
}
long plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int)s.size();
::s = s, ::t = t;
return n <= 16 ? s1() : s2();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8576 KB |
n = 2 |
2 |
Correct |
8 ms |
8576 KB |
n = 2 |
3 |
Correct |
8 ms |
8576 KB |
n = 2 |
4 |
Correct |
8 ms |
8576 KB |
n = 2 |
5 |
Correct |
8 ms |
8576 KB |
n = 2 |
6 |
Correct |
8 ms |
8576 KB |
n = 2 |
7 |
Correct |
8 ms |
8576 KB |
n = 3 |
8 |
Correct |
8 ms |
8576 KB |
n = 3 |
9 |
Correct |
8 ms |
8576 KB |
n = 3 |
10 |
Correct |
9 ms |
8576 KB |
n = 8 |
11 |
Correct |
9 ms |
8576 KB |
n = 8 |
12 |
Correct |
9 ms |
8576 KB |
n = 8 |
13 |
Correct |
8 ms |
8448 KB |
n = 8 |
14 |
Correct |
10 ms |
8448 KB |
n = 8 |
15 |
Correct |
8 ms |
8576 KB |
n = 8 |
16 |
Correct |
8 ms |
8576 KB |
n = 8 |
17 |
Correct |
8 ms |
8576 KB |
n = 8 |
18 |
Correct |
10 ms |
8576 KB |
n = 8 |
19 |
Correct |
9 ms |
8576 KB |
n = 3 |
20 |
Correct |
8 ms |
8576 KB |
n = 7 |
21 |
Correct |
9 ms |
8576 KB |
n = 8 |
22 |
Correct |
9 ms |
8576 KB |
n = 8 |
23 |
Correct |
9 ms |
8448 KB |
n = 8 |
24 |
Correct |
8 ms |
8576 KB |
n = 8 |
25 |
Correct |
8 ms |
8572 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8576 KB |
n = 2 |
2 |
Correct |
8 ms |
8576 KB |
n = 2 |
3 |
Correct |
8 ms |
8576 KB |
n = 2 |
4 |
Correct |
8 ms |
8576 KB |
n = 2 |
5 |
Correct |
8 ms |
8576 KB |
n = 2 |
6 |
Correct |
8 ms |
8576 KB |
n = 2 |
7 |
Correct |
8 ms |
8576 KB |
n = 3 |
8 |
Correct |
8 ms |
8576 KB |
n = 3 |
9 |
Correct |
8 ms |
8576 KB |
n = 3 |
10 |
Correct |
9 ms |
8576 KB |
n = 8 |
11 |
Correct |
9 ms |
8576 KB |
n = 8 |
12 |
Correct |
9 ms |
8576 KB |
n = 8 |
13 |
Correct |
8 ms |
8448 KB |
n = 8 |
14 |
Correct |
10 ms |
8448 KB |
n = 8 |
15 |
Correct |
8 ms |
8576 KB |
n = 8 |
16 |
Correct |
8 ms |
8576 KB |
n = 8 |
17 |
Correct |
8 ms |
8576 KB |
n = 8 |
18 |
Correct |
10 ms |
8576 KB |
n = 8 |
19 |
Correct |
9 ms |
8576 KB |
n = 3 |
20 |
Correct |
8 ms |
8576 KB |
n = 7 |
21 |
Correct |
9 ms |
8576 KB |
n = 8 |
22 |
Correct |
9 ms |
8576 KB |
n = 8 |
23 |
Correct |
9 ms |
8448 KB |
n = 8 |
24 |
Correct |
8 ms |
8576 KB |
n = 8 |
25 |
Correct |
8 ms |
8572 KB |
n = 8 |
26 |
Correct |
9 ms |
8576 KB |
n = 8 |
27 |
Correct |
19 ms |
8448 KB |
n = 8 |
28 |
Correct |
9 ms |
8576 KB |
n = 8 |
29 |
Correct |
83 ms |
8568 KB |
n = 16 |
30 |
Correct |
71 ms |
8568 KB |
n = 16 |
31 |
Correct |
73 ms |
8576 KB |
n = 16 |
32 |
Correct |
81 ms |
8576 KB |
n = 16 |
33 |
Correct |
70 ms |
8576 KB |
n = 16 |
34 |
Correct |
72 ms |
8576 KB |
n = 16 |
35 |
Correct |
60 ms |
8576 KB |
n = 16 |
36 |
Correct |
29 ms |
8704 KB |
n = 15 |
37 |
Correct |
8 ms |
8448 KB |
n = 8 |
38 |
Correct |
75 ms |
8576 KB |
n = 16 |
39 |
Correct |
71 ms |
8568 KB |
n = 16 |
40 |
Correct |
9 ms |
8576 KB |
n = 9 |
41 |
Correct |
76 ms |
8576 KB |
n = 16 |
42 |
Correct |
75 ms |
8568 KB |
n = 16 |
43 |
Correct |
78 ms |
8576 KB |
n = 16 |
44 |
Correct |
8 ms |
8576 KB |
n = 9 |
45 |
Correct |
31 ms |
8576 KB |
n = 15 |
46 |
Correct |
77 ms |
8560 KB |
n = 16 |
47 |
Correct |
67 ms |
8568 KB |
n = 16 |
48 |
Correct |
67 ms |
8568 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
9296 KB |
n = 199999 |
2 |
Correct |
83 ms |
9320 KB |
n = 199991 |
3 |
Correct |
85 ms |
9320 KB |
n = 199993 |
4 |
Incorrect |
64 ms |
8140 KB |
answer is not correct: 1 instead of 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
8576 KB |
n = 2 |
2 |
Correct |
8 ms |
8576 KB |
n = 2 |
3 |
Correct |
8 ms |
8576 KB |
n = 2 |
4 |
Correct |
8 ms |
8576 KB |
n = 2 |
5 |
Correct |
8 ms |
8576 KB |
n = 2 |
6 |
Correct |
8 ms |
8576 KB |
n = 2 |
7 |
Correct |
8 ms |
8576 KB |
n = 3 |
8 |
Correct |
8 ms |
8576 KB |
n = 3 |
9 |
Correct |
8 ms |
8576 KB |
n = 3 |
10 |
Correct |
9 ms |
8576 KB |
n = 8 |
11 |
Correct |
9 ms |
8576 KB |
n = 8 |
12 |
Correct |
9 ms |
8576 KB |
n = 8 |
13 |
Correct |
8 ms |
8448 KB |
n = 8 |
14 |
Correct |
10 ms |
8448 KB |
n = 8 |
15 |
Correct |
8 ms |
8576 KB |
n = 8 |
16 |
Correct |
8 ms |
8576 KB |
n = 8 |
17 |
Correct |
8 ms |
8576 KB |
n = 8 |
18 |
Correct |
10 ms |
8576 KB |
n = 8 |
19 |
Correct |
9 ms |
8576 KB |
n = 3 |
20 |
Correct |
8 ms |
8576 KB |
n = 7 |
21 |
Correct |
9 ms |
8576 KB |
n = 8 |
22 |
Correct |
9 ms |
8576 KB |
n = 8 |
23 |
Correct |
9 ms |
8448 KB |
n = 8 |
24 |
Correct |
8 ms |
8576 KB |
n = 8 |
25 |
Correct |
8 ms |
8572 KB |
n = 8 |
26 |
Correct |
9 ms |
8576 KB |
n = 8 |
27 |
Correct |
19 ms |
8448 KB |
n = 8 |
28 |
Correct |
9 ms |
8576 KB |
n = 8 |
29 |
Correct |
83 ms |
8568 KB |
n = 16 |
30 |
Correct |
71 ms |
8568 KB |
n = 16 |
31 |
Correct |
73 ms |
8576 KB |
n = 16 |
32 |
Correct |
81 ms |
8576 KB |
n = 16 |
33 |
Correct |
70 ms |
8576 KB |
n = 16 |
34 |
Correct |
72 ms |
8576 KB |
n = 16 |
35 |
Correct |
60 ms |
8576 KB |
n = 16 |
36 |
Correct |
29 ms |
8704 KB |
n = 15 |
37 |
Correct |
8 ms |
8448 KB |
n = 8 |
38 |
Correct |
75 ms |
8576 KB |
n = 16 |
39 |
Correct |
71 ms |
8568 KB |
n = 16 |
40 |
Correct |
9 ms |
8576 KB |
n = 9 |
41 |
Correct |
76 ms |
8576 KB |
n = 16 |
42 |
Correct |
75 ms |
8568 KB |
n = 16 |
43 |
Correct |
78 ms |
8576 KB |
n = 16 |
44 |
Correct |
8 ms |
8576 KB |
n = 9 |
45 |
Correct |
31 ms |
8576 KB |
n = 15 |
46 |
Correct |
77 ms |
8560 KB |
n = 16 |
47 |
Correct |
67 ms |
8568 KB |
n = 16 |
48 |
Correct |
67 ms |
8568 KB |
n = 16 |
49 |
Correct |
88 ms |
9296 KB |
n = 199999 |
50 |
Correct |
83 ms |
9320 KB |
n = 199991 |
51 |
Correct |
85 ms |
9320 KB |
n = 199993 |
52 |
Incorrect |
64 ms |
8140 KB |
answer is not correct: 1 instead of 0 |
53 |
Halted |
0 ms |
0 KB |
- |