Submission #776955

#TimeUsernameProblemLanguageResultExecution timeMemory
776955qennethKnapsack (NOI18_knapsack)C++17
73 / 100
276 ms262144 KiB
#pragma GCC optimize("O3") #pragma GCC target("popcnt") #include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL) #define all(x) x.begin(), x.end() #define chmax(x, a) x = max(x, a); #define chmin(x, a) x = min(x, a); // usaco void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int MOD = 1e9 + 7; int main() { FASTIO; // setIO("snakes"); int s, n; cin >> s >> n; vector<vector<int>> a(n, vector<int>(3, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> a[i][j]; } } vector<vector<int>> dp(n + 1, vector<int> (s + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j <= s; j++) { // if (dp[i][j] == -1) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); for (int k = 0; k <= min(s, a[i][2]); k++) { if (j + k * a[i][1] <= s) { dp[i + 1][j + k * a[i][1]] = max(dp[i + 1][j + k * a[i][1]], dp[i][j] + k * a[i][0]); } } } } cout << dp[n][s] << "\n"; }

Compilation message (stderr)

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