제출 #830850

#제출 시각아이디문제언어결과실행 시간메모리
830850howard0027Knapsack (NOI18_knapsack)C++14
100 / 100
667 ms2408 KiB
//knapsack.cpp #include<cstdio> #include<vector> #include<algorithm> #include<deque> #include<utility> int main() { int s, n; int dp[2001] = {0}; scanf("%d%d", &s, &n); //s = 2000, n = 100000; for (int i = 0; i < n; ++i) { int v, w, k; scanf("%d%d%d", &v, &w, &k); //v = 1000000, w = 1, k = 1000000000; for (int r = 0; r < w; ++r) { //std::deque<std::pair<int, int>> dq; int dq[2001][2]; int head = 0, tail = 0; for (int q = 0; w * q + r <= s; ++q) { //while (dq.size() && dq.front().second < q - std::min(q, k)) while (tail - head > 0 && dq[head][1] < q - std::min(q, k)) { //dq.pop_front(); ++head; } //while (dq.size() && dq.back().first <= dp[w * q + r] - q * v) while (tail - head > 0 && dq[tail - 1][0] <= dp[w * q + r] - q * v) { //dq.pop_back(); --tail; } //dq.push_back(std::make_pair(dp[w * q + r] - q * v, q)); dq[tail][0] = dp[w * q + r] - q * v; dq[tail][1] = q; ++tail; //dp[w * q + r] = dq.front().first + q * v; dp[w * q + r] = dq[head][0] + 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:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   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...