제출 #911821

#제출 시각아이디문제언어결과실행 시간메모리
911821anastasiskolioKnapsack (NOI18_knapsack)C++14
37 / 100
1077 ms19548 KiB
#include <bits/stdc++.h> using namespace std; int main() { int S, N; scanf("%d%d", &S, &N); int V[N + 1]; int W[N + 1]; int K[N + 1]; int M = 0; for (int i = 1; i <= N; i++) { scanf("%d%d%d", &V[i], &W[i], &K[i]); M += K[i]; } int Weight[M + 1]; int Value[M + 1]; int m = 0; for (int i = 1; i <= N; i++) { int j = K[i]; while (j--) { m++; Weight[m] = W[i]; Value[m] = V[i]; } } long long dp[2][S + 1]; dp[1][0] = 0; for (int s = 0; s <= S; s++) dp[0][s] = 0; for (int i = 1; i <= M; i++) { for (int s = 1; s <= S; s++) { dp[i%2][s] = dp[(i - 1)%2][s]; if (s - Weight[i] >= 0) dp[i%2][s] = max(dp[i%2][s], dp[(i - 1)%2][s - Weight[i]] + Value[i]); } } printf("%lld\n", dp[M%2][S]); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |   scanf("%d%d", &S, &N);
      |   ~~~~~^~~~~~~~~~~~~~~~
knapsack.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d%d%d", &V[i], &W[i], &K[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...