Submission #21051

# Submission time Handle Problem Language Result Execution time Memory
21051 2017-04-04T05:24:44 Z sbansalcs Watching (JOI13_watching) C++14
0 / 100
3 ms 17692 KB
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2001;
ll arr[N];
int A[N],B[N];
int dp[N][N];
int n,p,q;

int bs(int f,ll a)   {
    int lx=f+1,rx=n,mx;
    while (lx<rx) {
        mx=(lx+rx)/2;
        if(arr[mx]>=a)  rx=mx;
        else    lx=mx+1;
    }
    return lx;
}





bool check(ll w)   {
    for (int i=1; i<=n; i++) {
        A[i]=bs(i,arr[i]+w);
        B[i]=bs(i,arr[i]+2*w);
    }
    for (int i=n+1; i>=1; i--) {
        for (int j=0; j<=q; j++) {
            if(i==n+1)  dp[i][j]=0;
            else    {
                ll a;
                a=arr[i]+w;
                dp[i][j]=1+dp[A[i]][j];
                if(j!=0)    {
                    dp[i][j]=min(dp[i][j],dp[B[i]][j-1]);
                    dp[i][j]=min(dp[i][j],dp[i][j-1]);
                }
            }
        }
    }
    return dp[1][q]<=p;
}

int main() {
    scanf("%d %d %d",&n,&p,&q);
    for (int i=1; i<=n; i++) {
        scanf("%lld",arr+i);
    }
    if(p+q>=n)  {
        cout<<1<<endl;return 0;
    }
    sort(arr+1,arr+1+n);
    

    
    arr[n+1]=2e9;
    int lx=1,rx=1e9,mx;
    while (lx<rx) {
        mx=(lx+rx)/2;
        if(check(mx))   rx=mx;
        else    lx=mx+1;
    }
    cout<<lx<<endl;
    return 0;
}

Compilation message

watching.cpp: In function 'bool check(ll)':
watching.cpp:34:20: warning: variable 'a' set but not used [-Wunused-but-set-variable]
                 ll a;
                    ^
watching.cpp: In function 'int main()':
watching.cpp:48:31: 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:50:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",arr+i);
                            ^

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 17692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 17692 KB Output isn't correct
2 Halted 0 ms 0 KB -