Submission #59139

#TimeUsernameProblemLanguageResultExecution timeMemory
59139RezwanArefin01Watching (JOI13_watching)C++17
0 / 100
147 ms16896 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int N = 2010; int n, p, q, a[N], dp[N][N], w; int f(int pos, int tot) { if(pos == n) return 0; int &ret = dp[pos][p]; if(~ret) return ret; ret = 1e9; int x = lower_bound(a + pos, a + n, a[pos] + w) - a; int y = lower_bound(a + pos, a + n, a[pos] + w + w) - a; if(tot < p) ret = f(x, tot + 1); return ret = min(ret, 1 + f(y, tot)); } int main(int argc, char const *argv[]) { scanf("%d %d %d", &n, &p, &q); for(int i = 0; i < n; i++) scanf("%d", &a[i]); p = min(p, n); sort(a, a + n); int lo = 1, hi = 1e9, ans = -1; while(lo <= hi) { w = lo + hi >> 1; memset(dp, -1, sizeof dp); if(f(0, 0) <= q) { ans = w, hi = w - 1; } else lo = w + 1; } printf("%d\n", ans); }

Compilation message (stderr)

watching.cpp: In function 'int main(int, const char**)':
watching.cpp:28:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   w = lo + hi >> 1; 
       ~~~^~~~
watching.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &p, &q); 
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]); 
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...