Submission #1104965

#TimeUsernameProblemLanguageResultExecution timeMemory
1104965The_EurekaKnapsack (NOI18_knapsack)C++17
37 / 100
2 ms592 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define alls(x) x.begin(), x.end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, n) for (int i = 1; i <= int(n); i++)
#define sz(x) int(x.size())
#define dbg(x) cerr << #x << " = " << x << endl;
#define cin std::cin
#define cout std::cout
#define pii pair<int, int>
#define pll pair<ll, ll>ip
const ld eps = 1e-12;
const ll inf = 1e16;
const ll mod = 998244353;
const ll mod1 = 1e9 + 87;
const ll mod2 = 1e9 + 93;
using namespace std;

void IOS(string name = "") {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false); // see /general/fast-io
    if (sz(name)) {
        freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
        freopen((name + ".out").c_str(), "w", stdout);
    }
}

struct node {
    int w;
    int v;
};

int main() {
    IOS();
    int n, W;
    cin >> W >> n;
    vector<node> objects;
    rep(i, n) {
        int v, w, m;
        cin >> v >> w >> m;
        int c = 1;
        while (m > c) {
            m -= c;
            objects.pb((node){w * c, v * c});
            c *= 2;
        }
        objects.pb((node){w * m, v * m});
    }
    vector<ll> dp(W + 1, 0);
    for (auto [w, v]: objects) {
        for (int j = W; j >= w; j--) {
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }
    cout << dp[W] << endl;
    return 0;
}

Compilation message (stderr)

knapsack.cpp: In function 'void IOS(std::string)':
knapsack.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         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...