제출 #755345

#제출 시각아이디문제언어결과실행 시간메모리
755345SriniVKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
/*
	Date: 09.06.2023
	Time:
	Learnt:
	Rating:
*/
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define bits(x) __builtin_popcount(x)
#define pb push_back
#define trav(name , ds) for(auto&name : ds)
#define f first
#define s second
#define clr(ds) ds.clear()
#define all(ds) ds.begin() , ds.end()
#define pi pair<int , int>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define rsz(ds ,size , val) ds.assign(size , val);
using namespace std;

size_t hF(pair<int , int> a){
	return (a.first + a.second)*(a.first + a.second + 1)/2 + a.second;
}
void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0);
	if (name.size()) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}
ll s , n;
vll gain , cost;
void solve(){
	cin >> s >> n;
	for(int i =0;i<n;i++){
			ll v , w , k;
			cin >> v >> w >> k;
			k = min(k , (int)ceil(s/(ld)w));
			for(int j= 0;j<k;j++)
				{
						gain.pb(v);
						cost.pb(w);
				}
	}
	n = gain.size();
	vector<vll> dp(n+1 , vll(s+1 , 0));//dp[i][j] -> Maximum value with cost j using first i elements

	for(int i = 0;i<n;i++){
			if(i==0){
						if(cost[i] <= s)
							dp[0][cost[i]] = gain[0];
						continue;
				}

			for(int j = 1;j<=s;j++){
					dp[i][j] = dp[i-1][j];
				if(cost[i] <= j ){
							dp[i][j] = max(dp[i][j] , dp[i-1][j-cost[i]] + gain[i]);
					}
			}
	}
	ll ans = 0;
	for(int i = 0 ;i<=s;i++)
		ans = max(ans , dp[n-1][i]);
	cout << ans << "\n";
}
int main(){
	setIO();
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}	
}

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:42:34: error: no matching function for call to 'min(ll&, int)'
   42 |    k = min(k , (int)ceil(s/(ld)w));
      |                                  ^
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:7:
/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:42:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |    k = min(k , (int)ceil(s/(ld)w));
      |                                  ^
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:7:
/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:42:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |    k = min(k , (int)ceil(s/(ld)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:7:
/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:42:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |    k = min(k , (int)ceil(s/(ld)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:7:
/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:42:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |    k = min(k , (int)ceil(s/(ld)w));
      |                                  ^
knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~