Submission #13359

# Submission time Handle Problem Language Result Execution time Memory
13359 2015-02-13T16:55:44 Z gs14004 Watching (JOI13_watching) C++14
Compilation error
0 ms 0 KB
#include <cstdio>
#include <algorithm>
using namespace std;

int n,p,q,a[2005];
int nxt[2005], nxt2[2005];

char dp[105][105][105];

bool f(int x, int y, int z){
    if(y == -1 || z == -1) return 0;
    if(x == n) return 1;
    if(~dp[x][y][z]) return dp[x][y][z];
    return dp[x][y][z] = f(nxt[x],y-1,z) || f(nxt2[x],y,z-1);
}

bool trial(int x){
    for (int i=0; i<n; i++) {
        nxt[i] = (int)(lower_bound(a,a+n,a[i]+x) - a);
        nxt2[i] = (int)(lower_bound(a,a+n,a[i]+2*x) - a);
    }
    memset(dp,-1,sizeof(dp));
    return f(0,p,q);
}

int main(){
    scanf("%d %d %d",&n,&p,&q);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    p = min(p,n);
    q = min(q,n);
    sort(a,a+n);
    int s = 0, e = 5e8;
    while (s != e) {
        int m = (s+e)/2;
        if(trial(m)) e = m;
        else s = m+1;
    }
    printf("%d",s);
}

Compilation message

watching.cpp: In function ‘bool f(int, int, int)’:
watching.cpp:14:60: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     return dp[x][y][z] = f(nxt[x],y-1,z) || f(nxt2[x],y,z-1);
                                                            ^
watching.cpp: In function ‘bool trial(int)’:
watching.cpp:22:28: error: ‘memset’ was not declared in this scope
     memset(dp,-1,sizeof(dp));
                            ^
watching.cpp: In function ‘int main()’:
watching.cpp:27: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:29:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^