제출 #447957

#제출 시각아이디문제언어결과실행 시간메모리
447957kakayoshiKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> data; typedef pair<ll, pair<ll,ll> > super; typedef vector <ll> vii; #define forw(i,a,b) for (ll i=a;i<=b;i++) #define forb(i,a,b) for (ll i=a;i>=b;i--) #define fast {ios::sync_with_stdio(false); cin.tie(0); } #define fi first #define se second #define pu push #define puf push_front #define pb push_back #define pof pop_front #define pob pop_back #define fr front #define all(a) a.begin(),a.end() const ll oo=1e18; const ll mod=1e9+7; const ll maxN=3e5+5; const int tx[4]={0,0,1,-1}; const int ty[4]={1,-1,0,1}; const ll base=31; int dp[2005],n,S,v,w,k; vector <int > save[2005]; vector <int> pre[2005]; void solve() { cin>>S>>n; forw(i,1,n) { cin>>v>>w>>k; forw(j,1,min(S/w,k)) save[w].pb(v); } forw(i,1,S) if (save[i].size()) { sort(all(save[i]),greater<ll>()); ll length=save[i].size()-1; pre[i].pb(0); forw(j,0,min(length,S/i)) { //cout<<save[i][j]<<" "; pre[i].pb(pre[i][j]+save[i][j]); } //cout<<endl; } forw(i,1,S) if (save[i].size()) { forb(w,S,1) forw(k,0,save[i].size()-1) { if (w-i*(k+1)<0) break; dp[w]=max(dp[w],dp[w-i*(k+1)]+pre[i][k+1]); } } ll ans=0; forw(i,1,S) ans=max(ans,dp[i]); cout<<ans; } int main() { fast; //freopen("test.inp","r",stdin); //freopen("test.out","w",stdout); int t=1; //cin>>t; while (t--) solve(); return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:7:34: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forw(i,a,b) for (ll i=a;i<=b;i++)
......
   54 |             forw(k,0,save[i].size()-1)
      |                  ~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:54:13: note: in expansion of macro 'forw'
   54 |             forw(k,0,save[i].size()-1)
      |             ^~~~
knapsack.cpp:62:26: error: no matching function for call to 'max(ll&, int&)'
   62 |         ans=max(ans,dp[i]);
      |                          ^
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: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:
knapsack.cpp:62:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   62 |         ans=max(ans,dp[i]);
      |                          ^
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: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:
knapsack.cpp:62:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   62 |         ans=max(ans,dp[i]);
      |                          ^
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:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
knapsack.cpp:62:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   62 |         ans=max(ans,dp[i]);
      |                          ^
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:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
knapsack.cpp:62:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   62 |         ans=max(ans,dp[i]);
      |                          ^