제출 #642464

#제출 시각아이디문제언어결과실행 시간메모리
642464burak_ozzkanKnapsack (NOI18_knapsack)C++14
100 / 100
180 ms248252 KiB
#include <bits/stdc++.h> #define nl '\n' #define int long long using namespace std; struct item { int value; int piece; }; void solve(){ int s, n; cin >> s >> n; vector< vector<item> > a(2005); for(int i = 0, w; i < n; i++){ item tmp; cin >> tmp.value >> w >> tmp.piece; a[w].push_back(tmp); } vector<int> weights; vector<int> values; for(int i = 1; i < 2005; i++){ sort(a[i].begin(), a[i].end(), [&](item a, item b){ return a.value > b.value; }); int currWeight = 0; bool flag = 0; for(auto x : a[i]){ if(flag) break; for(int j = 0; j < x.piece; j++){ if(currWeight+i > s) { flag = 1; break; } currWeight += i; weights.push_back(i); values.push_back(x.value); } } } vector< vector<int> > dp(values.size()+1, vector<int>(s+1, 0)); for(int i = 1; i < values.size()+1; i++){ for(int j = 1; j < s+1; j++){ dp[i][j] = dp[i-1][j]; if(j-weights[i-1] >= 0) dp[i][j] = max(dp[i][j], values[i-1]+dp[i-1][j-weights[i-1]]); } } cout << dp[values.size()][s] << nl; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; /*cin >> t;*/ while(t--) solve(); }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:41:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 1; i < values.size()+1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...