제출 #919437

#제출 시각아이디문제언어결과실행 시간메모리
919437imannKnapsack (NOI18_knapsack)C++17
73 / 100
145 ms262144 KiB
#include <iostream> #include <vector> #include <cmath> typedef long long ll; const int MAX_N = 1000*100 + 10; const int MAX_S = 2*1000 + 10; int Vs[MAX_N]; int Ws[MAX_N]; int Ks[MAX_N]; int dp[MAX_N][MAX_S]; void build_e(std::vector<int> &WWs, std::vector<int> &VVs, int num, int w, int v) { if (num <= 0) return; int c = std::log2(num + 1); int t = 1; for (int j = 0; j < c; j++) { WWs.push_back(t * w); VVs.push_back(t * v); t *= 2; } build_e(WWs, VVs, num - (t - 1), w, v); } std::pair<std::vector<int>, std::vector<int> > build(int n) { std::vector<int> WWs, VVs; for (int i = 0; i < n; ++i) build_e(WWs, VVs, Ks[i], Ws[i], Vs[i]); return {WWs, VVs}; } int solve(const std::vector<int> &WWs, const std::vector<int> &VVs, int s) { for (int j = 1; j <= s; ++j) { if (j >= WWs[0]) dp[0][j] = VVs[0]; } for (int i = 1; i < WWs.size(); ++i) { for (int j = 1; j <= s; ++j) { dp[i][j] = std::max(dp[i][j], dp[i - 1][j]); if (WWs[i] <= j) dp[i][j] = std::max(dp[i][j], dp[i - 1][j - WWs[i]] + VVs[i]); } } return dp[WWs.size() - 1][s]; } int main() { int s, n; std::cin >> s >> n; for (int i = 0; i < n; ++i) { std::cin >> Vs[i] >> Ws[i] >> Ks[i]; Ks[i] = std::min(Ks[i], s); } auto vecs = build(n); std::cout << solve(vecs.first, vecs.second, s) << std::endl; }

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

knapsack.cpp: In function 'int solve(const std::vector<int>&, const std::vector<int>&, int)':
knapsack.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int i = 1; i < WWs.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...