Submission #745514

#TimeUsernameProblemLanguageResultExecution timeMemory
745514sleepntsheepWatching (JOI13_watching)C++17
100 / 100
226 ms16084 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, p, q, a[N], dp[N][N]; int ok(int w) { memset(dp, 63, sizeof dp); dp[0][0] = 0; for (int i = 1; i <= n; ++i) { auto ip = max(0l, upper_bound(a, a+i, a[i] - w) - a - 1); auto iq = max(0l, upper_bound(a, a+i, a[i] - 2*w) - a - 1); for (int j = 0; j <= p; ++j) { if (j) { dp[i][j] = min(dp[i][j], dp[ip][j-1]); } dp[i][j] = min(dp[i][j], dp[iq][j] + 1); } } for (int j = 0; j <= p; ++j) if (dp[n][j] <= q) return 1; return 0; } int main() { scanf("%d%d%d", &n, &p, &q); p = min(p, n); q = min(q, n); for (int i = 1; i <= n; ++i) scanf("%d", a+i); sort(a+1, a+n+1); int l = 0, r = 1e9+2; while (r - l > 1) { auto m = (l+r)/2; if (ok(m)) r = m; else l = m; } printf("%d", r); return 0; }

Compilation message (stderr)

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