Submission #537050

#TimeUsernameProblemLanguageResultExecution timeMemory
537050pavementWatching (JOI13_watching)C++17
50 / 100
1101 ms15868 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") int a[2005], dp[2005][2005]; int main() { int n, p, q; scanf("%d%d%d", &n, &p, &q); q = min(q, n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int lo = 1, hi = a[n - 1] - a[0] + 1, ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; dp[0][0] = 1; for (int i = 1; i <= q; i++) dp[0][i] = 0; for (int i = 1; i < n; i++) { for (int j = 0; j <= q; j++) { int dpp = lower_bound(a, a + i + 1, a[i] - mid + 1) - a - 1, dpq = lower_bound(a, a + i + 1, a[i] - 2 * mid + 1) - a - 1; if (dpq < 0 && j) dp[i][j] = 0; else if (dpp < 0) dp[i][j] = 1; else if (j) dp[i][j] = min(dp[dpp][j] + 1, dp[dpq][j - 1]); else dp[i][j] = dp[dpp][0] + 1; } } if (dp[n - 1][q] <= p) ans = mid, hi = mid - 1; else lo = mid + 1; } printf("%d\n", ans); }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d%d", &n, &p, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
      |                              ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...