#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
int N;
int S[200000], T[200000];
long long dp[1<<16][16];
int E[400001];
bool f() {
vector<int> xs;
rep(i, N) xs.pb(S[i]), xs.pb(T[i]);
sort(all(xs)); uniq(xs);
rep(i, N) E[index(xs, S[i])]++, E[index(xs, T[i])]--;
rep(i, xs.size()) E[i+1] += E[i];
//cout<<"{"; rep(i, xs.size()) cout << E[i]<<",";cout<<"}\n";
rep(i, xs.size()) if (E[i] > 1) return false;
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:28:3: note: in expansion of macro 'rep'
rep(i, xs.size()) E[i+1] += E[i];
^
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:30:3: note: in expansion of macro 'rep'
rep(i, xs.size()) if (E[i] > 1) return false;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
n = 2 |
2 |
Correct |
1 ms |
376 KB |
n = 2 |
3 |
Correct |
1 ms |
428 KB |
n = 2 |
4 |
Correct |
1 ms |
500 KB |
n = 2 |
5 |
Correct |
2 ms |
520 KB |
n = 2 |
6 |
Correct |
1 ms |
556 KB |
n = 2 |
7 |
Correct |
1 ms |
604 KB |
n = 3 |
8 |
Correct |
1 ms |
608 KB |
n = 3 |
9 |
Correct |
1 ms |
608 KB |
n = 3 |
10 |
Correct |
1 ms |
608 KB |
n = 8 |
11 |
Correct |
1 ms |
620 KB |
n = 8 |
12 |
Correct |
1 ms |
624 KB |
n = 8 |
13 |
Correct |
1 ms |
624 KB |
n = 8 |
14 |
Correct |
2 ms |
624 KB |
n = 8 |
15 |
Correct |
1 ms |
624 KB |
n = 8 |
16 |
Correct |
1 ms |
704 KB |
n = 8 |
17 |
Correct |
1 ms |
704 KB |
n = 8 |
18 |
Correct |
1 ms |
704 KB |
n = 8 |
19 |
Correct |
1 ms |
704 KB |
n = 3 |
20 |
Correct |
1 ms |
704 KB |
n = 7 |
21 |
Correct |
1 ms |
704 KB |
n = 8 |
22 |
Correct |
1 ms |
704 KB |
n = 8 |
23 |
Correct |
1 ms |
704 KB |
n = 8 |
24 |
Correct |
1 ms |
704 KB |
n = 8 |
25 |
Correct |
1 ms |
704 KB |
n = 8 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
n = 2 |
2 |
Correct |
1 ms |
376 KB |
n = 2 |
3 |
Correct |
1 ms |
428 KB |
n = 2 |
4 |
Correct |
1 ms |
500 KB |
n = 2 |
5 |
Correct |
2 ms |
520 KB |
n = 2 |
6 |
Correct |
1 ms |
556 KB |
n = 2 |
7 |
Correct |
1 ms |
604 KB |
n = 3 |
8 |
Correct |
1 ms |
608 KB |
n = 3 |
9 |
Correct |
1 ms |
608 KB |
n = 3 |
10 |
Correct |
1 ms |
608 KB |
n = 8 |
11 |
Correct |
1 ms |
620 KB |
n = 8 |
12 |
Correct |
1 ms |
624 KB |
n = 8 |
13 |
Correct |
1 ms |
624 KB |
n = 8 |
14 |
Correct |
2 ms |
624 KB |
n = 8 |
15 |
Correct |
1 ms |
624 KB |
n = 8 |
16 |
Correct |
1 ms |
704 KB |
n = 8 |
17 |
Correct |
1 ms |
704 KB |
n = 8 |
18 |
Correct |
1 ms |
704 KB |
n = 8 |
19 |
Correct |
1 ms |
704 KB |
n = 3 |
20 |
Correct |
1 ms |
704 KB |
n = 7 |
21 |
Correct |
1 ms |
704 KB |
n = 8 |
22 |
Correct |
1 ms |
704 KB |
n = 8 |
23 |
Correct |
1 ms |
704 KB |
n = 8 |
24 |
Correct |
1 ms |
704 KB |
n = 8 |
25 |
Correct |
1 ms |
704 KB |
n = 8 |
26 |
Correct |
1 ms |
704 KB |
n = 8 |
27 |
Correct |
2 ms |
704 KB |
n = 8 |
28 |
Correct |
1 ms |
704 KB |
n = 8 |
29 |
Correct |
49 ms |
8940 KB |
n = 16 |
30 |
Correct |
47 ms |
8940 KB |
n = 16 |
31 |
Correct |
47 ms |
8940 KB |
n = 16 |
32 |
Correct |
45 ms |
8940 KB |
n = 16 |
33 |
Correct |
45 ms |
8940 KB |
n = 16 |
34 |
Correct |
45 ms |
8944 KB |
n = 16 |
35 |
Correct |
45 ms |
8944 KB |
n = 16 |
36 |
Correct |
22 ms |
8944 KB |
n = 15 |
37 |
Correct |
2 ms |
8944 KB |
n = 8 |
38 |
Correct |
45 ms |
8944 KB |
n = 16 |
39 |
Correct |
45 ms |
8944 KB |
n = 16 |
40 |
Correct |
2 ms |
8944 KB |
n = 9 |
41 |
Correct |
45 ms |
8944 KB |
n = 16 |
42 |
Correct |
48 ms |
8944 KB |
n = 16 |
43 |
Correct |
45 ms |
8944 KB |
n = 16 |
44 |
Correct |
2 ms |
8944 KB |
n = 9 |
45 |
Correct |
21 ms |
8944 KB |
n = 15 |
46 |
Correct |
45 ms |
8944 KB |
n = 16 |
47 |
Correct |
45 ms |
8944 KB |
n = 16 |
48 |
Correct |
45 ms |
8944 KB |
n = 16 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
8944 KB |
n = 199999 |
2 |
Correct |
215 ms |
8944 KB |
n = 199991 |
3 |
Correct |
197 ms |
8944 KB |
n = 199993 |
4 |
Correct |
137 ms |
8944 KB |
n = 152076 |
5 |
Correct |
86 ms |
8944 KB |
n = 93249 |
6 |
Correct |
173 ms |
12812 KB |
n = 199910 |
7 |
Correct |
184 ms |
16304 KB |
n = 199999 |
8 |
Correct |
180 ms |
18736 KB |
n = 199997 |
9 |
Correct |
163 ms |
21116 KB |
n = 171294 |
10 |
Correct |
129 ms |
22632 KB |
n = 140872 |
11 |
Incorrect |
171 ms |
27512 KB |
answer is not correct: 0 instead of 1 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
376 KB |
n = 2 |
2 |
Correct |
1 ms |
376 KB |
n = 2 |
3 |
Correct |
1 ms |
428 KB |
n = 2 |
4 |
Correct |
1 ms |
500 KB |
n = 2 |
5 |
Correct |
2 ms |
520 KB |
n = 2 |
6 |
Correct |
1 ms |
556 KB |
n = 2 |
7 |
Correct |
1 ms |
604 KB |
n = 3 |
8 |
Correct |
1 ms |
608 KB |
n = 3 |
9 |
Correct |
1 ms |
608 KB |
n = 3 |
10 |
Correct |
1 ms |
608 KB |
n = 8 |
11 |
Correct |
1 ms |
620 KB |
n = 8 |
12 |
Correct |
1 ms |
624 KB |
n = 8 |
13 |
Correct |
1 ms |
624 KB |
n = 8 |
14 |
Correct |
2 ms |
624 KB |
n = 8 |
15 |
Correct |
1 ms |
624 KB |
n = 8 |
16 |
Correct |
1 ms |
704 KB |
n = 8 |
17 |
Correct |
1 ms |
704 KB |
n = 8 |
18 |
Correct |
1 ms |
704 KB |
n = 8 |
19 |
Correct |
1 ms |
704 KB |
n = 3 |
20 |
Correct |
1 ms |
704 KB |
n = 7 |
21 |
Correct |
1 ms |
704 KB |
n = 8 |
22 |
Correct |
1 ms |
704 KB |
n = 8 |
23 |
Correct |
1 ms |
704 KB |
n = 8 |
24 |
Correct |
1 ms |
704 KB |
n = 8 |
25 |
Correct |
1 ms |
704 KB |
n = 8 |
26 |
Correct |
1 ms |
704 KB |
n = 8 |
27 |
Correct |
2 ms |
704 KB |
n = 8 |
28 |
Correct |
1 ms |
704 KB |
n = 8 |
29 |
Correct |
49 ms |
8940 KB |
n = 16 |
30 |
Correct |
47 ms |
8940 KB |
n = 16 |
31 |
Correct |
47 ms |
8940 KB |
n = 16 |
32 |
Correct |
45 ms |
8940 KB |
n = 16 |
33 |
Correct |
45 ms |
8940 KB |
n = 16 |
34 |
Correct |
45 ms |
8944 KB |
n = 16 |
35 |
Correct |
45 ms |
8944 KB |
n = 16 |
36 |
Correct |
22 ms |
8944 KB |
n = 15 |
37 |
Correct |
2 ms |
8944 KB |
n = 8 |
38 |
Correct |
45 ms |
8944 KB |
n = 16 |
39 |
Correct |
45 ms |
8944 KB |
n = 16 |
40 |
Correct |
2 ms |
8944 KB |
n = 9 |
41 |
Correct |
45 ms |
8944 KB |
n = 16 |
42 |
Correct |
48 ms |
8944 KB |
n = 16 |
43 |
Correct |
45 ms |
8944 KB |
n = 16 |
44 |
Correct |
2 ms |
8944 KB |
n = 9 |
45 |
Correct |
21 ms |
8944 KB |
n = 15 |
46 |
Correct |
45 ms |
8944 KB |
n = 16 |
47 |
Correct |
45 ms |
8944 KB |
n = 16 |
48 |
Correct |
45 ms |
8944 KB |
n = 16 |
49 |
Correct |
193 ms |
8944 KB |
n = 199999 |
50 |
Correct |
215 ms |
8944 KB |
n = 199991 |
51 |
Correct |
197 ms |
8944 KB |
n = 199993 |
52 |
Correct |
137 ms |
8944 KB |
n = 152076 |
53 |
Correct |
86 ms |
8944 KB |
n = 93249 |
54 |
Correct |
173 ms |
12812 KB |
n = 199910 |
55 |
Correct |
184 ms |
16304 KB |
n = 199999 |
56 |
Correct |
180 ms |
18736 KB |
n = 199997 |
57 |
Correct |
163 ms |
21116 KB |
n = 171294 |
58 |
Correct |
129 ms |
22632 KB |
n = 140872 |
59 |
Incorrect |
171 ms |
27512 KB |
answer is not correct: 0 instead of 1 |
60 |
Halted |
0 ms |
0 KB |
- |