# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047397 | PanosPask | Circus (Balkan15_CIRCUS) | C++14 | 30 ms | 2396 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 <bits/stdc++.h>
#include "circus.h"
#define mp make_pair
using namespace std;
const int INF = 1e9 + 1;
typedef pair<int, int> pi;
int N, M;
vector<int> p;
// nxt[i]: Next rope in the path from p[i] to M
vector<int> nxt;
vector<int> minlen;
priority_queue<pi, vector<pi>, greater<pi>> q;
// Test if j can become the optimal next rope in the path from p[i] to M
void test(int i, int j)
{
if (i < 0 || i >= N) {
return;
}
if (abs(p[i] - p[j]) >= minlen[j] && abs(p[i] - p[j]) < minlen[i]) {
minlen[i] = abs(p[i] - p[j]);
nxt[i] = j;
q.push(mp(minlen[i], i));
}
}
void init(int n, int m, int P[]){
N = n;
M = m;
p.resize(N);
minlen.assign(N, INF);
nxt.resize(N);
for (int i = 0; i < N; i++) {
p[i] = P[i];
}
sort(p.begin(), p.end());
p.push_back(M);
minlen.push_back(0);
nxt.push_back(N);
q.push(mp(0, N));
while (!q.empty()) {
int i, d;
tie(d, i) = q.top();
q.pop();
if (minlen[i] < d) {
continue;
}
// Advance nxt[i]
int j;
if (nxt[i] < i) {
j = i + 1;
}
else {
j = i - 1;
}
test(j, nxt[i]);
// Advance i
int p_l = upper_bound(p.begin(), p.end(), p[i] - minlen[i]) - p.begin() - 1;
int p_r = lower_bound(p.begin(), p.end(), p[i] + minlen[i]) - p.begin();
test(p_l, i);
test(p_r, i);
}
}
int minLength(int D) {
int ans = M - D;
for (int i = 0; i < N; i++) {
if (abs(D - p[i]) >= minlen[i]) {
ans = min(ans, abs(D - p[i]));
}
}
return ans;
}
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... |