제출 #690479

#제출 시각아이디문제언어결과실행 시간메모리
690479vjudge1Knapsack (NOI18_knapsack)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int W, n; cin >> W >> n; vector<array<long long, 2>> a; // { (value, weight) } for (int i = 0; i < n; i++) { long long v, w; int cnt; cin >> v >> w >> cnt; cnt = min(cnt, W / w); int hbp = 31 - __builtin_clz(cnt); for (int k = 0; k < hbp; k++) { a.push_back({ v * (1 << k), w * (1 << k) }); } cnt -= (1 << hbp) - 1; for (int k = 0; k < 31; k++) { if (cnt >> k & 1) { a.push_back({ v * (1 << k), w * (1 << k) }); } } } n = a.size(); vector<long long> dp(W + 1, 0); for (int i = 1; i <= n; i++) { for (int w = W; w >= a[i - 1][1]; w--) { dp[w] = max( dp[w], dp[w - a[i - 1][1]] + a[i - 1][0] ); } } cout << *max_element(dp.begin(), dp.end()) << "\n"; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:16:29: error: no matching function for call to 'min(int&, long long int)'
   16 |         cnt = min(cnt, W / w);
      |                             ^
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 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:16:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   16 |         cnt = min(cnt, W / w);
      |                             ^
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 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:16:29: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   16 |         cnt = min(cnt, W / w);
      |                             ^
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:16:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   16 |         cnt = min(cnt, W / w);
      |                             ^
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:16:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   16 |         cnt = min(cnt, W / w);
      |                             ^