제출 #528456

#제출 시각아이디문제언어결과실행 시간메모리
528456theysoldtheworldKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
 
using namespace std;

struct Item {
  long long v , w , k;
};
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int S , N;
  cin >> S >> N;
  vector<Item> a(N);
  for (int i = 0 ; i < N ; i++) {
    cin >> a[i].v >> a[i].w >> a[i].k;
    a[i].k = min(a[i].k , S);
  }

  auto Get_candidates = [&](long long val) {
    vector<long long> c;
    int po = -1;
    for (int i = 30 ; i >= 0 ; i--) {
      long long cur = (1LL << i);
      if (cur & val) {
        if (po == -1) {
          po = (1 << i) - 1;
          c.push_back(1);
        }
        else {
          c.push_back(cur);
        }
      }
    }
    for (int i = 30 ; i >= 0 ; i--) {
      long long cur = (1LL << i);
      if (po & cur) {
        c.push_back(cur);
      }
    }
    return c;
  };
  
  vector<pair<long long , long long>> who;
  for (int i = 0 ; i < N ; i++) {
    vector<long long> c = Get_candidates(a[i].k);
    for (int j = 0 ; j < (int)c.size() ; j++) {
      long long cost = a[i].w * c[j];
      long long add = a[i].v * c[j];
      who.emplace_back(add , cost);
    }
  }
  vector<long long> dp(S + 1);
  vector<bool> Reachable(S + 1);
  Reachable[0] = true;
  for (int i = 0 ; i < (int)who.size() ; i++) {
    for (int j = S ; j >= 0 ; j--) {
      if (j + who[i].second <= S && Reachable[j]) {
        Reachable[who[i].second + j] = true;
        dp[who[i].second + j] = max(dp[who[i].second + j] , dp[j] + who[i].first);
      }
    }
  }
  cout << *max_element(dp.begin(),dp.end()) << '\n';
  return 0; 
}

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:17:28: error: no matching function for call to 'min(long long int&, int&)'
   17 |     a[i].k = min(a[i].k , S);
      |                            ^
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 knapsack.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:
knapsack.cpp:17:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |     a[i].k = min(a[i].k , S);
      |                            ^
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 knapsack.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:
knapsack.cpp:17:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |     a[i].k = min(a[i].k , S);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.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:
knapsack.cpp:17:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |     a[i].k = min(a[i].k , S);
      |                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.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:
knapsack.cpp:17:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |     a[i].k = min(a[i].k , S);
      |                            ^