제출 #726628

#제출 시각아이디문제언어결과실행 시간메모리
726628Azther0zKnapsack (NOI18_knapsack)C++11
100 / 100
149 ms35188 KiB
#include <bits/stdc++.h> using namespace std; struct ITEM { int value,copy; bool operator<(const ITEM item) { if(value!=item.value) return value>item.value; return copy>item.copy; } }; int main() { int s,n; cin >> s >> n; map<int,vector<ITEM>> weight; for(int i=0;i<n;i++) { int v,w,k; cin >> v >> w >> k; weight[w].push_back({v,k}); } long long result=0; vector<vector<long long>> dp(weight.size()+1,vector<long long>(s+1,-1)); dp[0][0]=0; int at=1; for(auto &ww:weight) { int w=ww.first; vector<ITEM> item=ww.second; sort(item.begin(),item.end()); for(int i=0;i<=s;i++) { dp[at][i]=dp[at-1][i]; int copy=0,idx=0,use=0; long long value=0; while((copy+1)*w<=i&&idx<item.size()) { copy++; value+=item[idx].value; if(dp[at-1][i-copy*w]!=-1) dp[at][i]=max(dp[at][i],dp[at-1][i-copy*w]+value); result=max(result,dp[at][i]); use++; if(use==item[idx].copy) { use=0; idx++; } } } at++; } cout << result; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ITEM>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    while((copy+1)*w<=i&&idx<item.size())
      |                         ~~~^~~~~~~~~~~~
#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...