제출 #1113923

#제출 시각아이디문제언어결과실행 시간메모리
1113923dyogorbKnapsack (NOI18_knapsack)C++14
100 / 100
93 ms3780 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int s, n; cin >> s >> n; vector<tuple<int, int, int>> entries; for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; entries.push_back({w, -v, k}); } sort(entries.begin(), entries.end()); vector<int> used(s + 1); vector<int> pw; vector<int> pv; for (const auto [w, v, k] : entries) { int total = s / w; int i = 0; while(used[w] < total && i < k){ used[w] ++; i ++; pv.push_back(v * -1); pw.push_back(w); } } vector<int> dp(s + 1, 0); for (int i = 0; i < pw.size(); i++) { int v = pv[i], w = pw[i]; for (int j = s; j > 0; j--) { if(j - w >= 0) dp[j] = max(dp[j], dp[j - w] + v); } } int ans = 0; for (int i = 0; i <= s; i++) { ans = max(ans, dp[i]); } cout << ans << endl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:24:21: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |     for (const auto [w, v, k] : entries)
      |                     ^
knapsack.cpp:39:23: 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 = 0; i < pw.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...