#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int maxn = 2e5 + 10;
ll dp[17][(1 << 17)];
pair < int, int > sec[maxn];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
int n = (int) s.size();
if (false)///if (n <= 17)
{
for (int i = 0; i < n; i ++)
for (int mask = 0; mask < (1 << n); mask ++)
dp[i][mask] = inf;
for (int i = 0; i < n; i ++)
dp[i][(1 << i)] = 0;
for (ll mask = 0; mask < (1 << n); mask ++)
{
for (int i = 0; i < n; i ++)
{
if ((mask & (1 << i)) == 0)
continue;
//cout << "state " << i << " " << mask << " " << dp[i][mask] << endl;
for (int j = 0; j < n; j ++)
{
if ((mask & (1 << j)) != 0)
continue;
int new_mask = (mask | (1 << j));
//cout << "transition " << j << " " << max(0, t[i] - s[j]) << " " << t[i] << " " << s[j] << endl;
dp[j][new_mask] = min(dp[j][new_mask], dp[i][mask] + (ll)max(0, t[i] - s[j]));
}
}
}
ll ans = inf;
for (int i = 0; i < n; i ++)
ans = min(ans, dp[i][(1 << n) - 1]);
return ans;
}
else
{
for (int i = 0; i < n; i ++)
{
sec[i + 1] = {t[i], s[i]};
}
sort(sec + 1, sec + n + 1);
vector < pair < int, int > > ord;
for (int i = 0; i < n; i ++)
{
ord.push_back({sec[i].second, i});
}
sort(ord.begin(), ord.end());
set < int > act;
for (int i = 1; i <= n; i ++)
act.insert(i);
bool start = false;
for (pair < int, int > cur : ord)
{
int lf = 1, rf = n;
while(lf <= rf)
{
int mf = (lf + rf) / 2;
if (sec[mf].first <= cur.first)
lf = mf + 1;
else
rf = mf - 1;
}
set < int > :: iterator it = act.lower_bound(lf);
if (it == act.begin())
{
if (start == true)
return 1;
start = true;
}
else
{
it = prev(it);
if (*it == cur.second)
{
if (it == act.begin())
{
if (start == true)
return 1;
start = true;
}
else
{
it = prev(it);
}
}
act.erase(it);
}
}
return 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
16700 KB |
n = 199999 |
2 |
Correct |
99 ms |
20576 KB |
n = 199991 |
3 |
Correct |
101 ms |
20528 KB |
n = 199993 |
4 |
Correct |
89 ms |
15944 KB |
n = 152076 |
5 |
Correct |
54 ms |
10948 KB |
n = 93249 |
6 |
Incorrect |
88 ms |
19388 KB |
answer is not correct: 1 instead of 0 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |