제출 #493260

#제출 시각아이디문제언어결과실행 시간메모리
493260HaYoungJoonKnapsack (NOI18_knapsack)C++14
12 / 100
2 ms1996 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; ll dp[20000][2001]; typedef pair<ll,ll> pii; vector<pii > pre[2001],items; bool cmp(pii A, pii B) { return A.first > B.first; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,S; cin >> S >> n; ll v,k,w; for (int i = 1; i <= n; i++) { cin >> v >> w >> k; pre[w].push_back({v,k}); } items.push_back({0,0}); for (int w = 1; w <= S; w++) { if (pre[w].empty()) continue; sort(pre[w].begin(),pre[w].end(),cmp); ll weight = S; for (int i = 0; i < pre[w].size() && weight > 0; i++) { for (int j = 1; j <= pre[w][i].second && weight > 0; j++) { weight -= w; if (weight < 0) break; items.push_back({w,pre[w][i].first}); } } } for (int i = 1; i < items.size(); i++) for (int j = 0; j <= S; j++) if (j - items[i].first >= 0) dp[i][j] = max(dp[i-1][j],dp[i-1][j - items[i].first ] + items[i].second); else dp[i][j] = dp[i][j-1]; cout << dp[items.size()-1][S]; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int i = 0; i < pre[w].size() && weight > 0; i++) {
      |                         ~~^~~~~~~~~~~~~~~
knapsack.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 1; i < items.size(); i++)
      |                     ~~^~~~~~~~~~~~~~
#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...