Submission #306081

# Submission time Handle Problem Language Result Execution time Memory
306081 2020-09-24T13:05:06 Z vipghn2003 Watching (JOI13_watching) C++14
100 / 100
227 ms 16000 KB
#include<bits/stdc++.h>

using namespace std;

const int N=2005;
int n,p,q,a[N],dp[N][N];

bool check(int w)
{
    int k1=1,k2=1;
    for(int i=1;i<=n;i++)
    {
        while(a[k1]<a[i]-w+1) k1++;
        while(a[k2]<a[i]-2*w+1) k2++;
        for(int j=0;j<=p;j++)
        {
            dp[i][j]=1e9;
            if(j) dp[i][j]=min(dp[i][j],dp[k1-1][j-1]);
            dp[i][j]=min(dp[i][j],dp[k2-1][j]+1);
        }
    }
    return (dp[n][p]<=q);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>p>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    if(p+q>=n) return cout<<1,0;
    int l=1,r=1e9,res;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(!check(mid)) l=mid+1;
        else
        {
            res=mid;
            r=mid-1;
        }
    }
    cout<<res;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:44:11: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     cout<<res;
      |           ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8448 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 8 ms 8448 KB Output is correct
8 Correct 24 ms 9344 KB Output is correct
9 Correct 102 ms 14208 KB Output is correct
10 Correct 227 ms 16000 KB Output is correct
11 Correct 18 ms 9088 KB Output is correct
12 Correct 126 ms 16000 KB Output is correct
13 Correct 7 ms 8448 KB Output is correct
14 Correct 8 ms 8576 KB Output is correct
15 Correct 8 ms 8448 KB Output is correct