답안 #493549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493549 2021-12-12T02:47:17 Z blue Candies (JOI18_candies) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;

int main()
{
  int N;
  cin >> N;
  
  vll A(1+N);
  for(int i = 1; i <= N; i++) cin >> A[i];
  
  vll res(N - (N/2));
  for(int j = 1; j <= N - (N/2); j++)
  {
    ll lo = 0;
    ll hi = 2'000'000'000LL;
    while(1)
    {
      ll mid = (lo+hi)/2;
      vector< pair<ll, int> > dp(1+N);
      dp[0] = {0, 0};
      dp[1] = max({0, 0}, {A[1] - mid, -1});
      for(int i = 2; i <= N; i++)
      {
        dp[i] = max(dp[i-1], {dp[i-2].first + A[i] - mid, dp[i-2].second - 1});
      }
      
      if(lo == hi)
      {
        cout << dp[N].first + dp[N].second*mid << '\n';
      }
      else
      {
        if(dp[N].second <= mid)
          hi = mid;
        else 
          lo = mid+1;
      }
    }
  }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:26:43: error: no matching function for call to 'max(<brace-enclosed initializer list>, <brace-enclosed initializer list>)'
   26 |       dp[1] = max({0, 0}, {A[1] - mid, -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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from candies.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:
candies.cpp:26:43: note:   couldn't deduce template parameter '_Tp'
   26 |       dp[1] = max({0, 0}, {A[1] - mid, -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/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from candies.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:
candies.cpp:26:43: note:   candidate expects 3 arguments, 2 provided
   26 |       dp[1] = max({0, 0}, {A[1] - mid, -1});
      |                                           ^