제출 #975004

#제출 시각아이디문제언어결과실행 시간메모리
975004vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
117 ms262144 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int s,n; vector<pair<int,int> > weight[2005]; vector<pair<int,int> > item; int dp[20005][2005]; int cek(int idx,int brt){ if(brt<0)return -1e15; if(idx==item.size())return 0; int &res=dp[idx][brt]; if(res!=-1)return res; pair<int,int>p=item[idx]; res=max(cek(idx+1,brt),cek(idx+1,brt-p.first)+p.second); return res; } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>s>>n; for(int r=1;r<=n;r++){ int v,w,k; cin>>v>>w>>k; weight[w].push_back({v,k}); } for(int d=1;d<=2000;d++){ sort(weight[d].begin(),weight[d].end()); int maks= 2000/d +1; while(maks>0 && !weight[d].empty()){ maks--; pair<int,int> &p=weight[d].back(); item.push_back({d,p.first}); p.second--; if(p.second==0){ weight[d].pop_back(); } } } memset(dp,-1,sizeof dp); cout<<cek(0,s); }

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

knapsack.cpp: In function 'long long int cek(long long int, long long int)':
knapsack.cpp:12:11: 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(idx==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...