Submission #559078

# Submission time Handle Problem Language Result Execution time Memory
559078 2022-05-09T10:55:35 Z groshi Watching (JOI13_watching) C++17
100 / 100
217 ms 16212 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,p,q;
vector<int> Q;
int dp[2020][2020];
bool check(int ile)
{
    for(int i=0;i<=n;i++)
        for(int j=0;j<=min(n,p);j++)
            dp[i][j]=1000000000;
    dp[0][0]=0;
    for(int i=1;i<=Q.size();i++)
    {
        int gdzie1=lower_bound(Q.begin(),Q.end(),Q[i-1]-2*ile+1)-Q.begin();
        int gdzie2=lower_bound(Q.begin(),Q.end(),Q[i-1]-ile+1)-Q.begin();
        for(int j=0;j<=min(n,p);j++)
        {
            if(j>0)
                dp[i][j]=min(dp[gdzie1][j]+1,dp[gdzie2][j-1]);
            else dp[i][j]=dp[gdzie1][j]+1;
        }
    }
    for(int i=0;i<=min(n,p);i++)
        if(dp[n][i]<=q)
            return 1;
    return 0;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>p>>q;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        Q.push_back(x);
    }
    sort(Q.begin(),Q.end());
    int pocz=0,kon=1000000005,sre,ostd;
    while(pocz<kon)
    {
        sre=(pocz+kon)/2;
        if(check(sre))
        {
            ostd=sre;
            kon=sre;
        }
        else pocz=sre+1;
    }
    cout<<ostd;
    return 0;
}

Compilation message

watching.cpp: In function 'bool check(int)':
watching.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=1;i<=Q.size();i++)
      |                 ~^~~~~~~~~~
watching.cpp: In function 'int main()':
watching.cpp:54:11: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     cout<<ostd;
      |           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 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 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8376 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 191 ms 16164 KB Output is correct
4 Correct 217 ms 16212 KB Output is correct
5 Correct 17 ms 8916 KB Output is correct
6 Correct 206 ms 16156 KB Output is correct
7 Correct 8 ms 8404 KB Output is correct
8 Correct 22 ms 9356 KB Output is correct
9 Correct 93 ms 14236 KB Output is correct
10 Correct 189 ms 16212 KB Output is correct
11 Correct 20 ms 9044 KB Output is correct
12 Correct 129 ms 16032 KB Output is correct
13 Correct 9 ms 8404 KB Output is correct
14 Correct 15 ms 8516 KB Output is correct
15 Correct 10 ms 8512 KB Output is correct