Submission #820178

#TimeUsernameProblemLanguageResultExecution timeMemory
820178upedKnapsack (NOI18_knapsack)C++14
17 / 100
186 ms262144 KiB
// // Created by MiłoszK on 11.08.2023. // // Two Sets II #include<bits/stdc++.h> using namespace std; using ll = long long; vector<ll> sieve(ll n) { vector<bool> is_prime(n + 1, true); is_prime[0] = is_prime[1] = false; for (ll i = 2; i <= n; i++) { if (is_prime[i] && (long long) i * i <= n) { for (ll j = i * i; j <= n; j += i) is_prime[j] = false; } } vector<ll> primes; for (ll i = 2; i <= n; ++i) { if (is_prime[i]) { primes.push_back(i); } } return primes; } void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void fileio(const string &name) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } //ll MOD = 1e9 + 7; //ll TWO_MOD_INV = 500000004; //struct Item { // int value; // int weight; // int amount; //}; int main() { fastio(); //vector<Item> items; ll s, n; cin >> s >> n; //items.resize(n); vector<pair<int, int>> vp; for (ll i = 0; i < n; ++i) { int v, w, k; cin >> v >> w >> k; for (int j = 1; j <= k; ++j) { if (w * j <= s) { vp.emplace_back(v * j, w * j); } } //items[i] = {v, w, k}; } // vector<ll> dp2(s + 1); // for (ll i = n - 1; i >= 0; --i) { // for (ll j = s; j >= items[i].weight; --j) { // for (ll k = 0; k <= items[i].amount && j - (items[i].weight * k) >= 0; ++k) { // dp2[j] = max(dp2[j], dp2[j - items[i].weight * k] + items[i].value * k); // } // } // } // cout << dp2[s]; vector<ll> dp2(s + 1); for (ll i = vp.size() - 1; i >= 0; --i) { for (ll j = s; j >= vp[i].second; --j) { dp2[j] = max(dp2[j], dp2[j - vp[i].second] + vp[i].first); } } cout << dp2[s]; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void fileio(const string&)':
knapsack.cpp:36:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     freopen((name + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen((name + ".out").c_str(), "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...