제출 #784370

#제출 시각아이디문제언어결과실행 시간메모리
784370makanhuliaKnapsack (NOI18_knapsack)C++17
73 / 100
111 ms39308 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; vector<pair<ll,ll>> bycost[2005]; vector<pair<ll,ll>> item; ll val[100005],cost[100005],freq[100005]; ll memo[2005][2005]; ll idx=0; ll dp(ll x,ll y){ if(x==item.size()) return 0; if(y<=0) return 0; if(memo[x][y]!=-1) return memo[x][y]; //lewat ll best=dp(x+1,y); //ambil if(y>=item[x].second){ best=max(best,dp(x+1,y-item[x].second)+item[x].first); } return memo[x][y]=best; } int main(){ int t,n;cin>>t>>n; for(ll i=1;i<=n;i++){ cin>>val[i]>>cost[i]>>freq[i]; bycost[cost[i]].push_back({val[i],freq[i]}); } bool masih=true; for(ll j=1;j<=2000;j++){ int tot=0; if(bycost[j].size()>0){ sort(bycost[j].begin(),bycost[j].end(),greater<pair<ll,ll>>()); for(auto nx:bycost[j]){ for(int i=1;i<=nx.second;i++){ tot+=j; item.push_back({nx.first,j}); idx++; if(tot>=2000){ break; masih=false; } } if(!masih) break; } } if(!masih) break; } memset(memo,-1,sizeof memo); cout<<dp(0,t); }

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

knapsack.cpp: In function 'long long int dp(long long int, long long int)':
knapsack.cpp:12:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   if(x==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...