Submission #633130

#TimeUsernameProblemLanguageResultExecution timeMemory
633130AlmaKnapsack (NOI18_knapsack)C++17
0 / 100
97 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } const int MX = 100'005; int S, N; int v[MX], w[MX], k[MX]; ll DP[MX][2'005]; ll knapsack (int i, int rem) { if (i == N or rem == 0) return 0; ll &ans = DP[i][rem]; if (ans != -1) return ans; if (rem < w[i]) return ans = knapsack(i+1, rem); for (int x = 0; x <= k[i] and rem >= w[i]*x; x++) { ans = max(ans, v[i]*x + knapsack(i+1, rem - w[i]*x)); } return ans; } int main() { setIO("std"); cin >> S >> N; for (int i = 0; i < N; i++) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i], S / w[i]); } memset(DP, -1, sizeof DP); cout << knapsack(0, S) << '\n'; return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void setIO(std::string)':
knapsack.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".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...