#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
const int N = 2e5+5;
int am[16][16];
ll res[16][(1<<16)+5];
ll dp(int i, int bm) {
if (bm == 0) return 0;
if (~res[i][bm]) return res[i][bm];
res[i][bm] = 1e18;
int x = bm;
while (x) {
int lso = x&-x;
int j = __builtin_ctz(lso);
res[i][bm] = min(res[i][bm], am[i][j] + dp(j, bm ^ lso));
x -= lso;
}
//cout << i << " " << bm << " :: " << res[i][bm] << endl;
return res[i][bm];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if (false && n <= 16) {
FOR(i, 0, n-1) {
FOR(j, 0, n-1) {
am[i][j] = max(0, t[i]-s[j]);
}
}
memset(res, -1, sizeof res);
ll ans = 1e18;
FOR(i, 0, n-1) ans = min(ans, dp(i, ((1<<n)-1)^(1<<i)));
return ans;
}
else {
multiset<int> out;
FOR(i, 0, n-1) {
out.insert(s[i]);
}
out.insert(1e9+10);
sort(t.begin(), t.end());
reverse(t.begin(), t.end());
FOR(i, 0, n-1) {
auto it = out.lower_bound(t[i]);
//for (auto x : out) cout << x << " " ; cout << endl;
if (it == out.end()) return 1;
else out.erase(it);
}
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 2 |
2 |
Correct |
3 ms |
384 KB |
n = 2 |
3 |
Correct |
3 ms |
384 KB |
n = 2 |
4 |
Correct |
1 ms |
384 KB |
n = 2 |
5 |
Correct |
3 ms |
384 KB |
n = 2 |
6 |
Incorrect |
1 ms |
384 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 2 |
2 |
Correct |
3 ms |
384 KB |
n = 2 |
3 |
Correct |
3 ms |
384 KB |
n = 2 |
4 |
Correct |
1 ms |
384 KB |
n = 2 |
5 |
Correct |
3 ms |
384 KB |
n = 2 |
6 |
Incorrect |
1 ms |
384 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
318 ms |
13000 KB |
n = 199999 |
2 |
Correct |
290 ms |
12900 KB |
n = 199991 |
3 |
Correct |
325 ms |
13036 KB |
n = 199993 |
4 |
Correct |
225 ms |
9848 KB |
n = 152076 |
5 |
Correct |
98 ms |
6136 KB |
n = 93249 |
6 |
Correct |
308 ms |
13020 KB |
n = 199910 |
7 |
Correct |
290 ms |
12980 KB |
n = 199999 |
8 |
Correct |
282 ms |
12920 KB |
n = 199997 |
9 |
Correct |
269 ms |
11140 KB |
n = 171294 |
10 |
Correct |
211 ms |
9124 KB |
n = 140872 |
11 |
Incorrect |
301 ms |
12884 KB |
answer is not correct: 0 instead of 1 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
n = 2 |
2 |
Correct |
3 ms |
384 KB |
n = 2 |
3 |
Correct |
3 ms |
384 KB |
n = 2 |
4 |
Correct |
1 ms |
384 KB |
n = 2 |
5 |
Correct |
3 ms |
384 KB |
n = 2 |
6 |
Incorrect |
1 ms |
384 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |