제출 #1033439

#제출 시각아이디문제언어결과실행 시간메모리
1033439cryptobunnyKnapsack (NOI18_knapsack)C++14
37 / 100
1 ms436 KiB
#include <iostream> #include <vector> #include <cassert> using namespace std; int main() { int s, n; cin >> s >> n; vector<int> val, cost; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; int j; for (j = 30; j >= 1; j--) { if (k >= (1 << j)) { break; } } for (int x = 0; x < j; x++) { val.push_back(v << x); cost.push_back(w << x); k -= 1 << x; } if (k) { val.push_back(v * k); cost.push_back(w * k); } } vector<int> dp(s + 1); int ans = 0; for (int i = 0; i < val.size(); i++) { assert(i < cost.size()); // cout << val[i] << " " << cost[i] << endl; for (int w = s; w >= cost[i]; w--) { dp[w] = max(dp[w], dp[w - cost[i]] + val[i]); ans = max(ans, dp[w]); } } cout << ans << endl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < val.size(); i++) {
      |                     ~~^~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from knapsack.cpp:3:
knapsack.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         assert(i < cost.size());
      |                ~~^~~~~~~~~~~~~
#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...