Submission #330028

#TimeUsernameProblemLanguageResultExecution timeMemory
330028dolphingarlicCircus (Balkan15_CIRCUS)C++14
100 / 100
769 ms10596 KiB
#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 = 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++) 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 (stderr)

grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...