Submission #444636

# Submission time Handle Problem Language Result Execution time Memory
444636 2021-07-14T13:26:33 Z osmanallazov Watching (JOI13_watching) C++14
100 / 100
292 ms 15964 KB
#include <bits/stdc++.h>
using namespace std;
int n,p,q;
int event[2002];
int dp[2001][2001];
bool check(int w){
    int sm=0,lr=0;
    for(int i=1;i<=n;i++){
        while(event[i]-event[sm+1]>=w){
            sm++;
        }
        while(event[i]-event[lr+1]>=2*w){
            lr++;
        }
        for(int j=0;j<=p;j++){
            dp[i][j]=2001;
            if(j){
                dp[i][j]=min(dp[i][j],dp[sm][j-1]);
            }
            dp[i][j]=min(dp[i][j],dp[lr][j]+1);
        }
    }
    return dp[n][p]<=q;
}
int main()
{
    cin>>n>>p>>q;
    if(p>n){
        p=n;
    }
    if(q>n){
        q=n;
    }
    for(int i=0;i<n;i++){
        cin>>event[i];
    }
    sort(event,event+n+1);
    int l=1,r=1e9,ans=1e9;
    while(l<=r){
        int mid=(l+r)/2;
        if(check(mid)){
            r=mid-1;
            ans=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 2 ms 684 KB Output is correct
12 Correct 2 ms 716 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8276 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 177 ms 15964 KB Output is correct
4 Correct 292 ms 15964 KB Output is correct
5 Correct 15 ms 8844 KB Output is correct
6 Correct 230 ms 15960 KB Output is correct
7 Correct 7 ms 8396 KB Output is correct
8 Correct 25 ms 9292 KB Output is correct
9 Correct 133 ms 14212 KB Output is correct
10 Correct 221 ms 15964 KB Output is correct
11 Correct 16 ms 9044 KB Output is correct
12 Correct 141 ms 15964 KB Output is correct
13 Correct 7 ms 8396 KB Output is correct
14 Correct 8 ms 8396 KB Output is correct
15 Correct 8 ms 8380 KB Output is correct