Submission #941691

#TimeUsernameProblemLanguageResultExecution timeMemory
941691yophisKnapsack (NOI18_knapsack)C++17
37 / 100
1051 ms33980 KiB
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <cmath> #include <cstdio> #include <map> #include <stack> #include <numeric> #include <queue> #include <climits> using namespace std; using ll = long long; using str = string; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; #define all(x) begin(x), end(x) #define lb lower_bound #define ub upper_bound #define pb push_back #define FOR(i,a,b) for (int i = (a); i < (b); ++i) const int INF = 1e9; void setIO(string filename = "") { ios_base::sync_with_stdio(false); cin.tie(0); if (filename.size()) { freopen((filename+".in").c_str(), "r", stdin); freopen((filename+".out").c_str(), "w", stdout); } } // ===================================== int n,s; int main() { setIO(); cin >> s >> n; vector<pii> v; FOR (i, 0, n) { int val, weight, cnt; cin>>val>>weight>>cnt; FOR (j, 0, cnt) v.pb({val, weight}); } vl dp(s+1); for (auto &[val, weight]: v) { for (int i=s;i>=0;i--) { ll left = i - weight; if (left >= 0) { dp[i] = max(dp[i], dp[left] + val); } } } cout << dp[s] << '\n'; }

Compilation message (stderr)

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