제출 #1005640

#제출 시각아이디문제언어결과실행 시간메모리
1005640kvintsekstakordKnapsack (NOI18_knapsack)C++17
100 / 100
127 ms255612 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; int S, N; vector<vector<pair<int, int> > > vk(2010, vector<pair<int, int>>()); vector<int> w={0}; vector<int> v={0}; int dp[2010][16000]; int32_t main() { cin >> S >> N; for(int i = 1; i <= N; i++){ int vi, wi, ki; cin >> vi >> wi >> ki; vk[wi].push_back({vi, ki}); } for(int i = 1; i <= 2000; i++){ sort(vk[i].begin(), vk[i].end(), greater<pair<int, int> >()); int sum = 0; for(int j = 0; j < vk[i].size(); j++){ int vi = vk[i][j].first; int k = vk[i][j].second; int e; if(sum+k<=(2000/i)){ e=k; sum+=k; }else{ e = (2000/i)-sum; sum = (2000)/i; } for(int z = 0; z < e; z++){ w.push_back(i); v.push_back(vi); } if(sum==(2000)/i) break; } } for(int i = 0; i <= w.size(); i++) dp[0][i]=0; for(int i = 0; i <= S; i++) dp[i][0]=0; for(int i = 1; i <= S; i++){ for(int j = 1; j < w.size(); j++){ if(i-w[j]<0) dp[i][j]=dp[i][j-1]; else{ dp[i][j]=max(dp[i][j-1], dp[i-w[j]][j-1]+v[j]); } } } cout << dp[S][w.size()-1]; return 0; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j = 0; j < vk[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~
knapsack.cpp:49:22: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(int i = 0; i <= w.size(); i++) dp[0][i]=0;
      |                    ~~^~~~~~~~~~~
knapsack.cpp:53:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j = 1; j < w.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...