Submission #1096049

#TimeUsernameProblemLanguageResultExecution timeMemory
1096049InvMODKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define siz(v) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e3+1; int S, n; ll dp[N], answer; vector<pair<ll,int>> bag; void process(ll v, ll w){ assert(w <= S); for(int i = S; i >= w; i--){ if(dp[i-w] != -1) ckmx(dp[i], dp[i-w] + v); ckmx(answer, dp[i]); } return; } void solve() { cin >> S >> n; for(int i = 1; i <= n; i++){ ll v,w,k; cin >> v >> w >> k; k = min(k, S); for(int j = 0; j < (32 - __builtin_clz(k)); j++){ if(k >= (1<<j)){ k -= (1<<j); if(w * (1ll<<j) > S) break; bag.push_back(make_pair(-v * (1ll<<j), w * (1ll<<j))); } else break; } if(k){ if(w * k > S) continue; bag.push_back(make_pair(-v * k, w * k)); } } sort(bag.begin(), bag.end()); fill(dp+1, dp+1+S, -1); for(int i = 0; (i < min((int)bag.size(), n+S)); i++){ process(-bag[i].first, bag[i].second); } cout << answer <<"\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:43:21: error: no matching function for call to 'min(ll&, int&)'
   43 |         k = min(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:43:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   43 |         k = min(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:43:21: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   43 |         k = min(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:43:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |         k = min(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:43:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   43 |         k = min(k, S);
      |                     ^
knapsack.cpp: In function 'int main()':
knapsack.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~