# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
329955 | 2020-11-23T09:00:36 Z | dolphingarlic | Circus (Balkan15_CIRCUS) | C++14 | 1094 ms | 524292 KB |
#include "circus.h" #include <bits/stdc++.h> using namespace std; struct State { int cost, idx, change_cnt; bool dir; // Left = 0 }; bool operator<(State A, State B) { return A.cost > B.cost; } int n, m; vector<int> p, mn; vector<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; p.push_back(m); mn = vector<int>(n + 1, INT_MAX); priority_queue<State> pq; pq.push({mn[n] = 0, n, 0, false}); while (pq.size()) { State curr = pq.top(); pq.pop(); if (curr.cost != mn[curr.idx]) continue; for (int i = 0; i < n; i++) { if (curr.change_cnt == 2 && i > curr.idx) break; if (abs(p[curr.idx] - p[i]) >= curr.cost && abs(p[curr.idx] - p[i]) < mn[i]) { bool dir = p[i] > p[curr.idx]; pq.push({mn[i] = abs(p[curr.idx] - p[i]), i, curr.change_cnt + (curr.dir ^ dir), dir}); } } } 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.back().first) to_right.push_back({p[i] + mn[i], p[i]}); reverse(to_right.begin(), to_right.end()); } 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 | Runtime error | 1094 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 49 ms | 4572 KB | Output is correct |
6 | Correct | 64 ms | 8664 KB | Output is correct |
7 | Correct | 54 ms | 4572 KB | Output is correct |
8 | Correct | 49 ms | 4572 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 49 ms | 4572 KB | Output is correct |
6 | Correct | 64 ms | 8664 KB | Output is correct |
7 | Correct | 54 ms | 4572 KB | Output is correct |
8 | Correct | 49 ms | 4572 KB | Output is correct |
9 | Correct | 482 ms | 17976 KB | Output is correct |
10 | Correct | 430 ms | 10768 KB | Output is correct |
11 | Correct | 413 ms | 10124 KB | Output is correct |
12 | Correct | 465 ms | 18992 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1094 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1094 ms | 524292 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |