#include "railroad.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF (1LL<<60)
#define INF2 1145141919
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define _1 first
#define _2 second
#define MAX_N (1<<19)
struct SegTree {
P seg[MAX_N*2-1];
SegTree() {
rep(i, MAX_N*2-1) seg[i] = P(INF2, -1);
}
void update(int k, P v) {
k += MAX_N-1;
while (k > 0) {
k = (k-1)/2;
seg[k] = min(seg[k*2+1], seg[k*2+2]);
}
}
P query(int a, int b, int k=0, int l=0, int r=MAX_N) {
if (b <= l || r <= a) return P(INF2, -1);
if (a <= l && r <= b) return seg[k];
return min(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
}
} rmq;
int N;
int S[200000], T[200000];
long long dp[1<<16][16];
vector<int> G[400000];
bool f() {
vector<int> xs;
rep(i, N) xs.pb(S[i]), xs.pb(T[i]);
sort(all(xs)); uniq(xs);
rep(i, N) G[index(xs, S[i])].pb(T[i]);
rep(i, xs.size()) sort(all(G[i]), greater<int>());
rep(i, xs.size()) if (!G[i].empty()) rmq.update(i, P(G[i].back(), i));
int s = 0;
rep(_, N) {
int p = rmq.query(s, MAX_N)._2;
if (p == -1) return false;
s = index(xs, G[p].back());
G[p].pop_back();
rmq.update(p, P(INF2, -1));
if (!G[p].empty()) rmq.update(p, P(G[p].back(), p));
}
return true;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
N = s.size();
rep(i, N) S[i] = s[i], T[i] = t[i];
//if( false){
if (N <= 16) {
rep(i, 1<<N) rep(j, N) dp[i][j] = INF;
rep(i, N) dp[1<<i][i] = 0;
rep(b, 1<<N) {
rep(last, N) {
if (dp[b][last] == INF) continue;
rep(t, N) if (((b>>t)&1) == 0) {
dp[b|(1<<t)][t] = min(dp[b|(1<<t)][t], dp[b][last] + max(T[last]-S[t], 0));
}
}
}
long long m = INF;
rep(i, N) m = min(m, dp[(1<<N)-1][i]);
return m;
}
else {
return !f();
}
}
Compilation message
railroad.cpp: In function 'bool f()':
railroad.cpp:8:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
railroad.cpp:47:3: note: in expansion of macro 'rep'
rep(i, xs.size()) sort(all(G[i]), greater<int>());
^
railroad.cpp:8:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
railroad.cpp:48:3: note: in expansion of macro 'rep'
rep(i, xs.size()) if (!G[i].empty()) rmq.update(i, P(G[i].back(), i));
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
17880 KB |
n = 2 |
2 |
Correct |
17 ms |
18020 KB |
n = 2 |
3 |
Correct |
17 ms |
18020 KB |
n = 2 |
4 |
Correct |
17 ms |
18020 KB |
n = 2 |
5 |
Correct |
16 ms |
18036 KB |
n = 2 |
6 |
Correct |
16 ms |
18088 KB |
n = 2 |
7 |
Correct |
17 ms |
18140 KB |
n = 3 |
8 |
Correct |
16 ms |
18140 KB |
n = 3 |
9 |
Correct |
16 ms |
18140 KB |
n = 3 |
10 |
Correct |
17 ms |
18140 KB |
n = 8 |
11 |
Correct |
17 ms |
18156 KB |
n = 8 |
12 |
Correct |
16 ms |
18156 KB |
n = 8 |
13 |
Correct |
17 ms |
18192 KB |
n = 8 |
14 |
Correct |
17 ms |
18284 KB |
n = 8 |
15 |
Correct |
16 ms |
18284 KB |
n = 8 |
16 |
Correct |
16 ms |
18284 KB |
n = 8 |
17 |
Correct |
16 ms |
18284 KB |
n = 8 |
18 |
Correct |
16 ms |
18284 KB |
n = 8 |
19 |
Correct |
17 ms |
18284 KB |
n = 3 |
20 |
Correct |
16 ms |
18284 KB |
n = 7 |
21 |
Correct |
15 ms |
18284 KB |
n = 8 |
22 |
Correct |
16 ms |
18284 KB |
n = 8 |
23 |
Correct |
17 ms |
18284 KB |
n = 8 |
24 |
Correct |
16 ms |
18284 KB |
n = 8 |
25 |
Correct |
17 ms |
18284 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
17880 KB |
n = 2 |
2 |
Correct |
17 ms |
18020 KB |
n = 2 |
3 |
Correct |
17 ms |
18020 KB |
n = 2 |
4 |
Correct |
17 ms |
18020 KB |
n = 2 |
5 |
Correct |
16 ms |
18036 KB |
n = 2 |
6 |
Correct |
16 ms |
18088 KB |
n = 2 |
7 |
Correct |
17 ms |
18140 KB |
n = 3 |
8 |
Correct |
16 ms |
18140 KB |
n = 3 |
9 |
Correct |
16 ms |
18140 KB |
n = 3 |
10 |
Correct |
17 ms |
18140 KB |
n = 8 |
11 |
Correct |
17 ms |
18156 KB |
n = 8 |
12 |
Correct |
16 ms |
18156 KB |
n = 8 |
13 |
Correct |
17 ms |
18192 KB |
n = 8 |
14 |
Correct |
17 ms |
18284 KB |
n = 8 |
15 |
Correct |
16 ms |
18284 KB |
n = 8 |
16 |
Correct |
16 ms |
18284 KB |
n = 8 |
17 |
Correct |
16 ms |
18284 KB |
n = 8 |
18 |
Correct |
16 ms |
18284 KB |
n = 8 |
19 |
Correct |
17 ms |
18284 KB |
n = 3 |
20 |
Correct |
16 ms |
18284 KB |
n = 7 |
21 |
Correct |
15 ms |
18284 KB |
n = 8 |
22 |
Correct |
16 ms |
18284 KB |
n = 8 |
23 |
Correct |
17 ms |
18284 KB |
n = 8 |
24 |
Correct |
16 ms |
18284 KB |
n = 8 |
25 |
Correct |
17 ms |
18284 KB |
n = 8 |
26 |
Correct |
16 ms |
18284 KB |
n = 8 |
27 |
Correct |
17 ms |
18284 KB |
n = 8 |
28 |
Correct |
16 ms |
18284 KB |
n = 8 |
29 |
Correct |
63 ms |
26348 KB |
n = 16 |
30 |
Correct |
64 ms |
26348 KB |
n = 16 |
31 |
Correct |
63 ms |
26424 KB |
n = 16 |
32 |
Correct |
62 ms |
26424 KB |
n = 16 |
33 |
Correct |
64 ms |
26424 KB |
n = 16 |
34 |
Correct |
62 ms |
26424 KB |
n = 16 |
35 |
Correct |
63 ms |
26424 KB |
n = 16 |
36 |
Correct |
38 ms |
26424 KB |
n = 15 |
37 |
Correct |
17 ms |
26424 KB |
n = 8 |
38 |
Correct |
63 ms |
26424 KB |
n = 16 |
39 |
Correct |
62 ms |
26476 KB |
n = 16 |
40 |
Correct |
17 ms |
26476 KB |
n = 9 |
41 |
Correct |
63 ms |
26476 KB |
n = 16 |
42 |
Correct |
69 ms |
26476 KB |
n = 16 |
43 |
Correct |
62 ms |
26476 KB |
n = 16 |
44 |
Correct |
16 ms |
26476 KB |
n = 9 |
45 |
Correct |
38 ms |
26476 KB |
n = 15 |
46 |
Correct |
63 ms |
26524 KB |
n = 16 |
47 |
Correct |
63 ms |
26524 KB |
n = 16 |
48 |
Correct |
62 ms |
26524 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
239 ms |
30780 KB |
answer is not correct: 1 instead of 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
17880 KB |
n = 2 |
2 |
Correct |
17 ms |
18020 KB |
n = 2 |
3 |
Correct |
17 ms |
18020 KB |
n = 2 |
4 |
Correct |
17 ms |
18020 KB |
n = 2 |
5 |
Correct |
16 ms |
18036 KB |
n = 2 |
6 |
Correct |
16 ms |
18088 KB |
n = 2 |
7 |
Correct |
17 ms |
18140 KB |
n = 3 |
8 |
Correct |
16 ms |
18140 KB |
n = 3 |
9 |
Correct |
16 ms |
18140 KB |
n = 3 |
10 |
Correct |
17 ms |
18140 KB |
n = 8 |
11 |
Correct |
17 ms |
18156 KB |
n = 8 |
12 |
Correct |
16 ms |
18156 KB |
n = 8 |
13 |
Correct |
17 ms |
18192 KB |
n = 8 |
14 |
Correct |
17 ms |
18284 KB |
n = 8 |
15 |
Correct |
16 ms |
18284 KB |
n = 8 |
16 |
Correct |
16 ms |
18284 KB |
n = 8 |
17 |
Correct |
16 ms |
18284 KB |
n = 8 |
18 |
Correct |
16 ms |
18284 KB |
n = 8 |
19 |
Correct |
17 ms |
18284 KB |
n = 3 |
20 |
Correct |
16 ms |
18284 KB |
n = 7 |
21 |
Correct |
15 ms |
18284 KB |
n = 8 |
22 |
Correct |
16 ms |
18284 KB |
n = 8 |
23 |
Correct |
17 ms |
18284 KB |
n = 8 |
24 |
Correct |
16 ms |
18284 KB |
n = 8 |
25 |
Correct |
17 ms |
18284 KB |
n = 8 |
26 |
Correct |
16 ms |
18284 KB |
n = 8 |
27 |
Correct |
17 ms |
18284 KB |
n = 8 |
28 |
Correct |
16 ms |
18284 KB |
n = 8 |
29 |
Correct |
63 ms |
26348 KB |
n = 16 |
30 |
Correct |
64 ms |
26348 KB |
n = 16 |
31 |
Correct |
63 ms |
26424 KB |
n = 16 |
32 |
Correct |
62 ms |
26424 KB |
n = 16 |
33 |
Correct |
64 ms |
26424 KB |
n = 16 |
34 |
Correct |
62 ms |
26424 KB |
n = 16 |
35 |
Correct |
63 ms |
26424 KB |
n = 16 |
36 |
Correct |
38 ms |
26424 KB |
n = 15 |
37 |
Correct |
17 ms |
26424 KB |
n = 8 |
38 |
Correct |
63 ms |
26424 KB |
n = 16 |
39 |
Correct |
62 ms |
26476 KB |
n = 16 |
40 |
Correct |
17 ms |
26476 KB |
n = 9 |
41 |
Correct |
63 ms |
26476 KB |
n = 16 |
42 |
Correct |
69 ms |
26476 KB |
n = 16 |
43 |
Correct |
62 ms |
26476 KB |
n = 16 |
44 |
Correct |
16 ms |
26476 KB |
n = 9 |
45 |
Correct |
38 ms |
26476 KB |
n = 15 |
46 |
Correct |
63 ms |
26524 KB |
n = 16 |
47 |
Correct |
63 ms |
26524 KB |
n = 16 |
48 |
Correct |
62 ms |
26524 KB |
n = 16 |
49 |
Incorrect |
239 ms |
30780 KB |
answer is not correct: 1 instead of 0 |
50 |
Halted |
0 ms |
0 KB |
- |