Submission #25426

# Submission time Handle Problem Language Result Execution time Memory
25426 2017-06-22T06:38:00 Z tlwpdus Watching (JOI13_watching) C++
100 / 100
283 ms 19268 KB
#include <bits/stdc++.h>

using namespace std;

int dyn[2100][2100];
int prev[2][2100];
int n, p, q;
int arr[2100];

bool ok(int w) {
    int i, j;
    for (i=1;i<=n;i++) {
        prev[0][i] = upper_bound(arr,arr+i,arr[i]-w)-arr-1;
        prev[1][i] = upper_bound(arr,arr+i,arr[i]-w*2)-arr-1;
    }
    for (i=1;i<=n;i++) {
        for (j=0;j<=n;j++) {
            dyn[i][j] = min(((j)?dyn[prev[1][i]][j-1]:987654321),dyn[prev[0][i]][j]+1);
        }
    }
    return dyn[n][min(q,n)]<=p;
}

int main() {
    int i;
    scanf("%d%d%d",&n,&p,&q);
    arr[0] = -(1e9+10);
    for (i=1;i<=n;i++) scanf("%d",&arr[i]);
    sort(arr,arr+n+1);
    int s = 1, e = 5e8+3;
    while(s<=e) {
        int m = (s+e)>>1;
        if (ok(m)) e = m-1;
        else s = m+1;
    }
    printf("%d\n",s);
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:26:29: 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:28:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=1;i<=n;i++) scanf("%d",&arr[i]);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 19268 KB Output is correct
2 Correct 0 ms 19268 KB Output is correct
3 Correct 0 ms 19268 KB Output is correct
4 Correct 0 ms 19268 KB Output is correct
5 Correct 0 ms 19268 KB Output is correct
6 Correct 0 ms 19268 KB Output is correct
7 Correct 0 ms 19268 KB Output is correct
8 Correct 0 ms 19268 KB Output is correct
9 Correct 0 ms 19268 KB Output is correct
10 Correct 0 ms 19268 KB Output is correct
11 Correct 0 ms 19268 KB Output is correct
12 Correct 0 ms 19268 KB Output is correct
13 Correct 0 ms 19268 KB Output is correct
14 Correct 0 ms 19268 KB Output is correct
15 Correct 0 ms 19268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 266 ms 19268 KB Output is correct
2 Correct 0 ms 19268 KB Output is correct
3 Correct 209 ms 19268 KB Output is correct
4 Correct 216 ms 19268 KB Output is correct
5 Correct 219 ms 19268 KB Output is correct
6 Correct 233 ms 19268 KB Output is correct
7 Correct 246 ms 19268 KB Output is correct
8 Correct 233 ms 19268 KB Output is correct
9 Correct 216 ms 19268 KB Output is correct
10 Correct 213 ms 19268 KB Output is correct
11 Correct 206 ms 19268 KB Output is correct
12 Correct 233 ms 19268 KB Output is correct
13 Correct 229 ms 19268 KB Output is correct
14 Correct 233 ms 19268 KB Output is correct
15 Correct 283 ms 19268 KB Output is correct