제출 #830845

#제출 시각아이디문제언어결과실행 시간메모리
830845howard0027Knapsack (NOI18_knapsack)C++14
73 / 100
1091 ms1300 KiB
//knapsack.cpp #include<cstdio> #include<vector> #include<algorithm> #include<deque> #include<utility> int main() { int s, n; std::vector<int> dp; scanf("%d%d", &s, &n); dp.resize(s + 1, 0); for (int i = 0; i < n; ++i) { int v, w, k; scanf("%d%d%d", &v, &w, &k); for (int r = 0; r < w; ++r) { std::deque<std::pair<int, int>> dq; for (int q = 0; w * q + r <= s; ++q) { while (dq.size() && dq.front().second < q - std::min(q, k)) { dq.pop_front(); } while (dq.size() && dq.back().first <= dp[w * q + r] - q * v) { dq.pop_back(); } dq.push_back(std::make_pair(dp[w * q + r] - q * v, q)); dp[w * q + r] = dq.front().first + q * v; //printf("dp[%d][%d] = %d\n", i, w * q + r, dp[w * q + r]); } } } printf("%d\n", dp[s]); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d", &s, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d%d", &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...