제출 #1047891

#제출 시각아이디문제언어결과실행 시간메모리
1047891manhlinh1501Knapsack (NOI18_knapsack)C++17
73 / 100
75 ms6632 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 1e5 + 5; struct PRODUCT { int c, w, x; PRODUCT(int c = 0, int w = 0, int x = 0) : c(c), w(w), x(x) {} }; int N, S; PRODUCT a[MAXN]; namespace subtask { const int MAXN = 105; const int MAXV = 2e3 + 5; i64 dp[MAXN][MAXV]; void solution() { for(int i = 1; i <= N; i++) { auto [c, w, x] = a[i]; for(int j = 0; j <= S; j++) dp[i][j] = dp[i - 1][j]; for(int z = 0; z <= x and z * w <= S; z++) { for(int j = S; j >= w * z; j--) dp[i][j] = max(dp[i][j], dp[i - 1][j - w * z] + 1LL * c * z); } } i64 ans = 0; for(int i = 1; i <= S; i++) ans = max(ans, dp[N][i]); cout << ans; } } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> S >> N; for(int i = 1; i <= N; i++) cin >> a[i].c >> a[i].w >> a[i].x; subtask::solution(); return (0 ^ 0); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...