Submission #1047397

#TimeUsernameProblemLanguageResultExecution timeMemory
1047397PanosPaskCircus (Balkan15_CIRCUS)C++14
11 / 100
30 ms2396 KiB
#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)

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...