제출 #844747

#제출 시각아이디문제언어결과실행 시간메모리
844747qrnoKnapsack (NOI18_knapsack)C++17
17 / 100
1 ms388 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int S, N; vector<int> V, W; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> S >> N; for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; int cnt = 1; for (; cnt <= k; cnt *= 2) { V.push_back(v * cnt); W.push_back(w * cnt); } if (k & (k+1)) { cnt = k - cnt/2; V.push_back(v * cnt); W.push_back(w * cnt); } } vector<int> most(S+1); for (int i = 0; i < size(V); i++) { for (int s = S; s-W[i] >= 0; s--) { most[s] = max(most[s], most[s-W[i]] + V[i]); } } cout << *max_element(begin(most), end(most)) << endl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:29:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for (int i = 0; i < size(V); 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...