Submission #492594

# Submission time Handle Problem Language Result Execution time Memory
492594 2021-12-08T05:25:22 Z ToroTN Watching (JOI13_watching) C++14
0 / 100
951 ms 32548 KB
#include<bits/stdc++.h>
using namespace std;
int n,p,q,a,st,md,ed,dp[2005][2005],val,idx,st1,st2,type;
vector<int> small[2005],large[2005],v;
int main()
{
    scanf("%d%d%d",&n,&p,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    st=1;
    ed=2e9;
    while(ed>=st)
    {
        md=(st+ed)/2;
        //printf("%d %d %d\n",st,md,ed);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                dp[i][j]=2e9;
            }
        }
        md=(st+ed)/2;
        for(int i=0;i<v.size()-1;i++)
        {
            val=v[i+1]+md-1;
            idx=upper_bound(v.begin(),v.end(),val)-v.begin()-1;
            //printf("%d %d\n",i,idx);
            small[idx].push_back(i);
        }
        //printf("\n");
        for(int i=0;i<v.size()-1;i++)
        {
            val=v[i+1]+2*md-1;
            idx=upper_bound(v.begin(),v.end(),val)-v.begin()-1;
            //printf("%d %d\n",i,idx);
            large[idx].push_back(i);
        }
        //printf("\n");
        st1=upper_bound(v.begin(),v.end(),v[0]+md-1)-v.begin()-1;
        st2=upper_bound(v.begin(),v.end(),v[0]+2*md-1)-v.begin()-1;
        //printf("%d %d\n",st1,st2);
        dp[st1][1]=min(dp[st1][1],0);
        dp[st2][0]=min(dp[st2][0],1);
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                for(int k=0;k<small[i].size();k++)
                {
                    if(j>0)
                    {
                        dp[i][j]=min(dp[i][j],dp[small[i][k]][j-1]);
                    }
                }
                for(int k=0;k<large[i].size();k++)
                {
                    dp[i][j]=min(dp[i][j],dp[large[i][k]][j]+1);
                }
            }
        }
        type=-1;
        for(int i=0;i<=p;i++)
        {
            if(dp[n-1][i]<=q)
            {
                type=0;
            }
        }
        if(type==0)
        {
            ed=md-1;
        }else
        {
            st=md+1;
        }
        for(int i=0;i<n;i++)
        {
            small[i].clear();
            large[i].clear();
        }
    }
    //printf("%d %d %d\n",st,md,ed);
    printf("%d\n",st);
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i=0;i<v.size()-1;i++)
      |                     ~^~~~~~~~~~~
watching.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i=0;i<v.size()-1;i++)
      |                     ~^~~~~~~~~~~
watching.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 for(int k=0;k<small[i].size();k++)
      |                             ~^~~~~~~~~~~~~~~~
watching.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int k=0;k<large[i].size();k++)
      |                             ~^~~~~~~~~~~~~~~~
watching.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d%d%d",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1484 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 951 ms 32548 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -