Submission #540564

#TimeUsernameProblemLanguageResultExecution timeMemory
540564ac2huKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "../templates/debug.h" #else #define deb(x...) #endif using namespace std; #define int unsigned long long int dp[(int)1e5 + 100][(int)2e3 + 10]; signed main() { iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int s,n;cin >> s >> n; vector<array<int,3>> items(n); for(int i = 0;i<n;i++){ for(int j = 0;j<3;j++)cin >> items[i][j]; } for(int i =0;i<n;i++){ for(int j = 0;j<=s;j++) dp[i + 1][j] = dp[i][j]; items[i][2] = min(items[i][2], (1 << (int)ceil(log2(s)))); while(items[i][2] > 0){ int lg = log2(items[i][2]); items[i][2] -= (1 << lg); for(int mask = 0;mask<=lg;mask++){ for(int j= 1;j<=s;j++){ dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]); int weight = items[i][1]*(1 << mask); int price = items[i][0]*(1 << mask); if(j >= weight) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight] + price); } } for(int j = 1;j<=s;j++) dp[i][j] = dp[i + 1][j]; } } cout << dp[n][s] << "\n"; }

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:21:73: error: no matching function for call to 'min(std::array<long long unsigned int, 3>::value_type&, int)'
   21 |                 items[i][2] = min(items[i][2], (1 << (int)ceil(log2(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:21:73: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'int')
   21 |                 items[i][2] = min(items[i][2], (1 << (int)ceil(log2(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:21:73: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'int')
   21 |                 items[i][2] = min(items[i][2], (1 << (int)ceil(log2(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:21:73: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   21 |                 items[i][2] = min(items[i][2], (1 << (int)ceil(log2(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:21:73: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   21 |                 items[i][2] = min(items[i][2], (1 << (int)ceil(log2(s))));
      |                                                                         ^