# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670837 | finn__ | Circus (Balkan15_CIRCUS) | C++17 | 19 ms | 2260 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "circus.h"
#include <bits/stdc++.h>
using namespace std;
vector<int64_t> p;
vector<int64_t> dp;
int64_t m;
int64_t min_height(int64_t d)
{
int64_t a = 0, b = 1e18;
while (a < b)
{
int64_t mid = (a + b) / 2;
size_t i = upper_bound(p.begin(), p.end(), d) - p.begin() - 1;
bool possible = 0;
while (i < p.size() && p[i] <= d + mid && !possible)
{
if (dp[i] <= p[i] - d)
possible = 1;
i++;
}
if (possible)
b = mid;
else
a = mid + 1;
}
return a;
}
void init(int N, int M, int P[])
{
m = M;
p = vector<int64_t>(N + 1);
dp = vector<int64_t>(N + 1);
p[N] = M;
dp[N] = 0;
copy(P, P + N, p.begin());
sort(p.begin(), p.end());
for (size_t i = 0; i < N + 1; i++)
dp[i] = max((int64_t)0, M - p[i]);
priority_queue<pair<int64_t, unsigned>, vector<pair<int64_t, unsigned>>, greater<pair<int64_t, unsigned>>> q;
q.push({0, lower_bound(p.begin(), p.end(), M) - p.begin()});
while (!q.empty())
{
auto const [h, u] = q.top();
q.pop();
if (h != dp[u])
continue;
size_t i = upper_bound(p.begin(), p.end(), p[u] + h) - p.begin();
while (i < p.size())
{
if (p[i] - p[u] < dp[i])
{
dp[i] = p[i] - p[u];
q.push({dp[i], i});
}
i++;
}
i = upper_bound(p.begin(), p.end(), p[u] - h) - p.begin() - 1;
while (i <= N)
{
if (p[u] - p[i] < dp[i])
{
dp[i] = p[u] - p[i];
q.push({dp[i], i});
}
i--;
}
}
}
int minLength(int D)
{
int64_t min_h = max((int64_t)0, m - D);
for (size_t i = 0; i < dp.size(); i++)
if (dp[i] <= abs(D - p[i]))
min_h = min(min_h, abs(D - p[i]));
return min_h;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |