Submission #228364

# Submission time Handle Problem Language Result Execution time Memory
228364 2020-04-30T18:55:17 Z Nayna Watching (JOI13_watching) C++14
100 / 100
296 ms 16096 KB
#include <bits/stdc++.h>

using namespace std;
const int mxn = 2e3+5;
typedef long long ll;
const int inf = 1e9+5;
int arr[mxn];
int dp[mxn][mxn];
int n, P, Q;

bool solve(int w)
{
    for(int i = 0; i <= n; i++)
        for(int r = 0; r <= n; r++) dp[i][r] = inf;
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        int x = upper_bound(arr+1, arr+n+1, arr[i]-w)-arr-1;
        int y = upper_bound(arr+1, arr+n+1, arr[i]-w-w)-arr-1;
        for(int r = 0; r <= P; r++)
        {
            if(r) dp[i][r] = min(dp[i][r], dp[x][r-1]);
            dp[i][r] = min(dp[i][r], dp[y][r]+1);
        }
    }
    for(int i = 0; i <= P; i++)
        if(dp[n][i]<=Q) return true;
    return false;
}
int main()
{

    scanf("%d%d%d", &n, &P, &Q);

    P = min(n, P);
    Q = min(n, Q);

    for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);

    sort(arr+1, arr+n+1);

    int lo = 1, hi = 1e9+5, ans = inf;

    while(lo<=hi)
    {
        int mid = (lo+hi)>>1;
        if(solve(mid))
        {
            hi = mid-1;
            ans = min(ans, mid);
        }
        else lo = mid+1;
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:33:10: 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:38:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);
                                 ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 6 ms 768 KB Output is correct
5 Correct 5 ms 896 KB Output is correct
6 Correct 6 ms 768 KB Output is correct
7 Correct 5 ms 768 KB Output is correct
8 Correct 5 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 5 ms 768 KB Output is correct
11 Correct 5 ms 768 KB Output is correct
12 Correct 5 ms 768 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 16000 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 235 ms 16000 KB Output is correct
4 Correct 296 ms 16088 KB Output is correct
5 Correct 89 ms 16092 KB Output is correct
6 Correct 283 ms 16088 KB Output is correct
7 Correct 81 ms 16000 KB Output is correct
8 Correct 95 ms 16000 KB Output is correct
9 Correct 169 ms 16000 KB Output is correct
10 Correct 282 ms 16000 KB Output is correct
11 Correct 91 ms 16000 KB Output is correct
12 Correct 193 ms 16000 KB Output is correct
13 Correct 86 ms 16000 KB Output is correct
14 Correct 86 ms 16000 KB Output is correct
15 Correct 87 ms 16096 KB Output is correct