Submission #559077

# Submission time Handle Problem Language Result Execution time Memory
559077 2022-05-09T10:54:59 Z groshi Watching (JOI13_watching) C++17
50 / 100
7 ms 8660 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,p,q;
vector<int> Q;
int dp[1020][1020];
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 2 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 708 KB Output is correct
10 Correct 1 ms 712 KB Output is correct
11 Correct 1 ms 708 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 Runtime error 7 ms 8660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -