제출 #553518

#제출 시각아이디문제언어결과실행 시간메모리
553518andrei_boaca수열 (APIO14_sequence)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,k,v[100005],s[100005];
ll dp[100005][205],from[100005][205];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    k++;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        s[i]=s[i-1]+v[i];
    }
    for(int i=1;i<=k;i++)
        dp[0][i]=1e17;
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=1e17;
        for(ll j=1;j<=k;j++)
        {
            dp[i][j]=1e17;
            for(ll l=i-1;l>=max(0LL,i-200);l--)
            {
                ll val=dp[l][j-1]+(s[i]-s[l])*(s[i]-s[l]);
                dp[i][j]=min(dp[i][j],val);
                if(dp[i][j]==val)
                    from[i][j]=l;
            }
        }
    }
    ll ans=dp[n][k];
    ans=s[n]*s[n]-ans;
    ans/=2;
    cout<<ans<<'\n';
    ll i=n;
    ll j=k;
    vector<ll> sol;
    while(i>0)
    {
        ll x=from[i][j];
        if(x>0)
            sol.push_back(x);
        i=x;
        j--;
    }
    reverse(sol.begin(),sol.end());
    for(int i:sol)
        cout<<i<<' ';
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int main()':
sequence.cpp:27:42: error: no matching function for call to 'max(long long int, int)'
   27 |             for(ll l=i-1;l>=max(0LL,i-200);l--)
      |                                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
sequence.cpp:27:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   27 |             for(ll l=i-1;l>=max(0LL,i-200);l--)
      |                                          ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
sequence.cpp:27:42: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   27 |             for(ll l=i-1;l>=max(0LL,i-200);l--)
      |                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
sequence.cpp:27:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |             for(ll l=i-1;l>=max(0LL,i-200);l--)
      |                                          ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from sequence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
sequence.cpp:27:42: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |             for(ll l=i-1;l>=max(0LL,i-200);l--)
      |                                          ^