Submission #709315

#TimeUsernameProblemLanguageResultExecution timeMemory
709315nima_aryanKnapsack (NOI18_knapsack)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #ifdef LOCAL #include "algo/debug.h" #endif using i64 = long long; template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<int> V(N + 1), W(N + 1), K(N + 1); for (int i = 1; i <= N; ++i) { cin >> V[i] >> W[i] >> K[i]; } vector dp(N + 1, vector<i64>(S + 1)); for (int i = 1; i <= N; ++i) { for (int sum = 0; sum <= S; ++sum) { for (int cnt = 0; sum - cnt * W[i] >= 0 && cnt <= K[i]; ++cnt) { dp[i][sum] = max(dp[i][sum], dp[i - 1][sum - cnt * W[i]] + cnt * V[i]); } } } cout << dp[N][S] << '\n'; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

Compilation message (stderr)

knapsack.cpp: In function 'int main()':
knapsack.cpp:41:11: error: missing template arguments before 'dp'
   41 |    vector dp(N + 1, vector<i64>(S + 1));
      |           ^~
knapsack.cpp:45:13: error: 'dp' was not declared in this scope
   45 |             dp[i][sum] = max(dp[i][sum], dp[i - 1][sum - cnt * W[i]] + cnt * V[i]);
      |             ^~
knapsack.cpp:49:12: error: 'dp' was not declared in this scope
   49 |    cout << dp[N][S] << '\n';
      |            ^~