제출 #1027156

#제출 시각아이디문제언어결과실행 시간메모리
1027156lmaobruhKnapsack (NOI18_knapsack)C++14
29 / 100
5 ms4696 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) const int N = 1e6+5, M = 2005; const ll inf = 1e18+5; ll s, n, v[N], w[N], k[N], dp1[M], dp2[M]; void sol() { cin >> s >> n; for (int i = 1; i <= n; ++i) cin >> v[i] >> w[i] >> k[i]; for (int i = 1; i <= s; ++i) dp1[i] = -inf; for (int i = 0; i < n; ++i) { for (int j = 0; j <= s; ++j) dp2[j] = -inf; for (int j = 0; j <= s; ++j) { ll cnt = min(k[i+1], (s-j)/w[i+1]); chmax(dp2[j+w[i+1]*cnt], dp1[j]+cnt*v[i+1]); chmax(dp2[j], dp1[j]); } swap(dp1, dp2); } ll ans = 0; for (int j = 0; j <= s; ++j) if (dp1[j] < inf) chmax(ans, dp1[j]); cout << ans; } signed main() { cin.tie(0) -> sync_with_stdio(0); if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin); int tc = 1, test = 0; // cin >> tc; while (++test <= tc) sol(); }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:34:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |   if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...