# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
330071 | 2020-11-23T16:43:30 Z | dolphingarlic | Circus (Balkan15_CIRCUS) | C++14 | 44 ms | 3556 KB |
#include "circus.h" #include <bits/stdc++.h> using namespace std; int n, m; vector<int> p, mn; deque<pair<int, int>> to_left, to_right; void init(int N, int M, int P[]) { for (int i = 0; i < N; i++) p.push_back(P[i]); sort(p.begin(), p.end()); p.erase(unique(p.begin(), p.end()), p.end()); n = p.size(), m = M; mn = vector<int>(n, INT_MAX); for (int i = n - 1; ~i; i--) { int dist = m - p[i]; auto lb = lower_bound(to_left.begin(), to_left.end(), make_pair(p[i], 0)); if (lb != to_left.end()) dist = min(dist, lb->second - p[i]); mn[i] = min(mn[i], dist); while (to_left.size() && p[i] - mn[i] >= to_left[0].first) to_left.pop_front(); to_left.push_front({p[i] - mn[i], p[i]}); } to_left.clear(); for (int i = 0; i < n; i++) { int dist = m - p[i]; auto ub = upper_bound(to_right.begin(), to_right.end(), make_pair(p[i], INT_MAX)); if (ub != to_right.begin()) dist = min(dist, p[i] - prev(ub)->second); mn[i] = min(mn[i], dist); while (to_right.size() && p[i] + mn[i] <= to_right.back().first) to_right.pop_back(); to_right.push_back({p[i] + mn[i], p[i]}); } to_right.clear(); for (int i = 0; i < n; i++) if (!to_left.size() || p[i] - mn[i] > to_left.back().first) to_left.push_back({p[i] - mn[i], p[i]}); for (int i = n - 1; ~i; i--) if (!to_right.size() || p[i] + mn[i] < to_right[0].first) to_right.push_front({p[i] + mn[i], p[i]}); } int minLength(int D) { int ans = m - D; auto lb = lower_bound(to_left.begin(), to_left.end(), make_pair(D, 0)); if (lb != to_left.end()) ans = min(ans, lb->second - D); auto ub = upper_bound(to_right.begin(), to_right.end(), make_pair(D, INT_MAX)); if (ub != to_right.begin()) ans = min(ans, D - prev(ub)->second); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 3300 KB | Output is correct |
2 | Correct | 44 ms | 3556 KB | Output is correct |
3 | Correct | 44 ms | 3428 KB | Output is correct |
4 | Correct | 43 ms | 3428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 3300 KB | Output is correct |
2 | Correct | 44 ms | 3556 KB | Output is correct |
3 | Correct | 44 ms | 3428 KB | Output is correct |
4 | Correct | 43 ms | 3428 KB | Output is correct |
5 | Incorrect | 1 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 3300 KB | Output is correct |
2 | Correct | 44 ms | 3556 KB | Output is correct |
3 | Correct | 44 ms | 3428 KB | Output is correct |
4 | Correct | 43 ms | 3428 KB | Output is correct |
5 | Incorrect | 1 ms | 364 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |