# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68311 | thebes | Watching (JOI13_watching) | C++14 | 513 ms | 16668 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MN = 2002;
int pos[MN], N, P, Q, i, lo, hi, l, r, k, nxt[MN], nxt2[MN], dp[MN][MN];
int solve(int n,int rem){
if(n == N+1) return 0;
else if(dp[n][rem]!=-1) return dp[n][rem];
if(rem) dp[n][rem]=min(solve(nxt[n],rem-1),solve(nxt2[n],rem)+1);
else dp[n][rem]=solve(nxt2[n],rem)+1;
return dp[n][rem];
}
bool check(int w){
for(l=r=k=1;l<=N;l++){
while(r<=N&&pos[r]-w+1<=pos[l]) r++;
while(k<=N&&pos[k]-2*w+1<=pos[l]) k++;
nxt[l] = r; nxt2[l] = k;
}
memset(dp, -1, sizeof(dp));
return solve(1,P)<=Q;
}
int main(){
for(scanf("%d%d%d",&N,&P,&Q),i=1;i<=N;i++)
scanf("%d",&pos[i]);
P = min(P, N);
sort(pos+1,pos+N+1);
lo = 1, hi = 1e9+7;
while(lo < hi){
int m = lo+hi>>1;
if(check(m)) hi=m;
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |