Submission #492589

# Submission time Handle Problem Language Result Execution time Memory
492589 2021-12-08T05:17:12 Z ToroTN Watching (JOI13_watching) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
long long n,p,q,a,st,md,ed,dp[2005][2005],val,idx,st1,st2,type;
vector<long long> small[2005],large[2005],v;
int main()
{
    scanf("%lld%lld%lld",&n,&p,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a);
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    st=1;
    ed=1e9;
    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]=1e9;
            }
        }
        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("%lld\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<long long 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<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i=0;i<v.size()-1;i++)
      |                     ~^~~~~~~~~~~
watching.cpp:47:36: error: no matching function for call to 'min(long long int&, int)'
   47 |         dp[st1][1]=min(dp[st1][1],0);
      |                                    ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
watching.cpp:47:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   47 |         dp[st1][1]=min(dp[st1][1],0);
      |                                    ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
watching.cpp:47:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   47 |         dp[st1][1]=min(dp[st1][1],0);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
watching.cpp:47:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |         dp[st1][1]=min(dp[st1][1],0);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
watching.cpp:47:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |         dp[st1][1]=min(dp[st1][1],0);
      |                                    ^
watching.cpp:48:36: error: no matching function for call to 'min(long long int&, int)'
   48 |         dp[st2][0]=min(dp[st2][0],1);
      |                                    ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
watching.cpp:48:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |         dp[st2][0]=min(dp[st2][0],1);
      |                                    ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
watching.cpp:48:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   48 |         dp[st2][0]=min(dp[st2][0],1);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
watching.cpp:48:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |         dp[st2][0]=min(dp[st2][0],1);
      |                                    ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from watching.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
watching.cpp:48:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   48 |         dp[st2][0]=min(dp[st2][0],1);
      |                                    ^
watching.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long 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<long long 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("%lld%lld%lld",&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("%lld",&a);
      |         ~~~~~^~~~~~~~~~~