제출 #975653

#제출 시각아이디문제언어결과실행 시간메모리
975653vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
524 ms161876 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define AC ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fs first #define sc second #define pb push_back const int inf=INT_MAX; vector<pii> a[2007]; vector<pii> item; int dp[20007][2007]; int C, n; int knapsack(int i, int C){ if(C < 0)return -inf; if(i==item.size())return 0; if(dp[i][C] != -1)return dp[i][C]; int w = item[i].sc, v= item[i].fs; return dp[i][C]= max(knapsack(i+1, C), knapsack(i+1, C-w)+v); } int main() { AC cin >> C >> n; for(int i=0; i<n; i++){ int v, w, k; cin >> v >> w >> k; a[w].pb({v,k}); } for(int w=1; w<=2000; w++){ sort(a[w].begin(), a[w].end()); int used = ceil(C/w); while(used and !a[w].empty()){ auto &[v, k] = a[w].back(); item.pb({a[w].back().fs, w}); used--, k--; if(k==0)a[w].pop_back(); } } memset(dp, -1, sizeof(dp)); cout << knapsack(0, C); }

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

knapsack.cpp: In function 'int knapsack(int, int)':
knapsack.cpp:20:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  if(i==item.size())return 0;
      |     ~^~~~~~~~~~~~~
#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...