제출 #482681

#제출 시각아이디문제언어결과실행 시간메모리
482681OlympiaKnapsack (NOI18_knapsack)C++17
29 / 100
3 ms304 KiB
#include <cmath> #include <iostream> #include <set> #include <climits> #include <algorithm> #include <cassert> #include <vector> #include <iomanip> #include <type_traits> #include <string> #include <queue> #include <map> using namespace std; #define ll long long struct item { long long weight; long long worth; long long cnt; }; int main() { long long S, N; cin >> S >> N; vector<item> items; for (int i = 0; i < N; i++) { long long wei, wor; cin >> wor >> wei; long long cnt; cin >> cnt; items.push_back({wei, wor, min(cnt, S/wei)}); } long long dp[S + 1]; for (int j = 0; j <= S; j++) { dp[j] = 0; } long long myMax = 0; for (int i = 1; i <= items.size(); i++) { for (int j = S; j >= 0; j--) { int cntr = 0; while (cntr * items[i - 1].weight <= j && cntr <= items[i - 1].cnt) { long long prev = dp[j]; dp[j] = max(dp[j], dp[j - cntr * items[i - 1].weight] + cntr * items[i - 1].worth); if (dp[j] == prev && cntr != 0) { break; } cntr++; } myMax = max(myMax, dp[j]); } } cout << myMax << endl; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<item>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     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...