Submission #661502

# Submission time Handle Problem Language Result Execution time Memory
661502 2022-11-26T00:37:57 Z sofija6 Watching (JOI13_watching) C++14
100 / 100
843 ms 63352 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXN 2010
using namespace std;
ll a[MAXN],n,p,q;
pair<ll,ll> dp[MAXN][MAXN];
ll Last(ll pos)
{
    ll l=1,r=n,mid,ans;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (a[mid]<=pos)
        {
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;
    }
    return ans;
}
bool Check(ll w)
{
    for (ll i=0;i<=n+1;i++)
    {
        for (ll j=0;j<=min(n,p);j++)
            dp[i][j]={0,LLONG_MAX};
    }
    dp[1][0]={1,0};
    for (ll i=1;i<=n;i++)
    {
        for (ll j=0;j<=min(n,p);j++)
        {
            if (!dp[i][j].first)
                continue;
            if (j<p)
            {
                ll pos=Last(a[i]+w-1);
                dp[pos+1][j+1].first=1;
                dp[pos+1][j+1].second=min(dp[pos+1][j+1].second,dp[i][j].second);
            }
            if (dp[i][j].second<q)
            {
                ll pos=Last(a[i]+2*w-1);
                dp[pos+1][j].first=1;
                dp[pos+1][j].second=min(dp[pos+1][j].second,dp[i][j].second+1);
            }
        }
    }
    for (ll i=0;i<=p;i++)
    {
        if (dp[n+1][i].first && dp[n+1][i].second<=q)
            return true;
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> p >> q;
    for (ll i=1;i<=n;i++)
        cin >> a[i];
    sort(a+1,a+1+n);
    ll l=1,r=1e9,mid,ans;
    while (l<=r)
    {
        mid=(l+r)/2;
        if (Check(mid))
        {
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    cout << ans;
    return 0;
}

Compilation message

watching.cpp: In function 'long long int Last(long long int)':
watching.cpp:21:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |     return ans;
      |            ^~~
watching.cpp: In function 'bool Check(long long int)':
watching.cpp:46:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |                 dp[pos+1][j].first=1;
      |                    ~~~^~
watching.cpp:40:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |                 dp[pos+1][j+1].first=1;
      |                    ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 724 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 3 ms 852 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 0 ms 724 KB Output is correct
14 Correct 0 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8404 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 716 ms 55368 KB Output is correct
4 Correct 430 ms 63352 KB Output is correct
5 Correct 69 ms 10836 KB Output is correct
6 Correct 843 ms 63340 KB Output is correct
7 Correct 7 ms 8916 KB Output is correct
8 Correct 87 ms 12360 KB Output is correct
9 Correct 234 ms 31988 KB Output is correct
10 Correct 469 ms 63332 KB Output is correct
11 Correct 86 ms 11348 KB Output is correct
12 Correct 528 ms 39128 KB Output is correct
13 Correct 7 ms 8788 KB Output is correct
14 Correct 11 ms 9052 KB Output is correct
15 Correct 9 ms 8916 KB Output is correct