제출 #1095361

#제출 시각아이디문제언어결과실행 시간메모리
1095361ihneKnapsack (NOI18_knapsack)C++17
100 / 100
44 ms3744 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back const int mn=2000+5; struct ITEM{ int v,w,k; ITEM () {} ITEM(int _v,int _w,int _k):v(_v),w(_w),k(_k){} bool operator < (const ITEM& o) const { return v<o.v; } } item[100005]; int dp[mn]; vector<int> v[mn]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int s,n; cin>>s>>n; for (int i=1;i<=n;i++){ cin>>item[i].v>>item[i].w>>item[i].k; } sort(item+1,item+n+1); for (int i=n;i>=1;i--){ while (item[i].k&&v[item[i].w].size()<s/item[i].w){ item[i].k--; v[item[i].w].pb(item[i].v); } } for (int i=1;i<=s;i++){ if (v[i].empty()) continue; for (int j=0;j<v[i].size();j++){ for (int k=s;k>=i;k--){ dp[k]=max(dp[k],dp[k-i]+v[i][j]); } } } cout<<dp[s]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:25:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while (item[i].k&&v[item[i].w].size()<s/item[i].w){
      |                       ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
knapsack.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int j=0;j<v[i].size();j++){
      |                  ~^~~~~~~~~~~~
#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...