제출 #1020962

#제출 시각아이디문제언어결과실행 시간메모리
1020962urejgiKnapsack (NOI18_knapsack)C++17
73 / 100
1077 ms16096 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ int s, n; scanf("%lld %lld", &s, &n); vector<int> value, weight; int v, w, k; for (int i = 0; i < n; ++i) { scanf("%lld %lld %lld", &v, &w, &k); int count = 1; while (k > 0) { int currentCount = min(count, k); value.push_back(currentCount * v); weight.push_back(currentCount * w); k -= currentCount; count <<= 1; } } int totalItems = value.size(); vector<int> dp(s + 1, 0); for (int i = 0; i < totalItems; ++i) { for (int j = s; j >= weight[i]; --j) { dp[j] = max(dp[j], dp[j - weight[i]] + value[i]); } } printf("%lld\n", dp[s]); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%lld %lld", &s, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%lld %lld %lld", &v, &w, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...