Submission #1050827

#TimeUsernameProblemLanguageResultExecution timeMemory
1050827trandangquangKnapsack (NOI18_knapsack)C++17
73 / 100
1043 ms36808 KiB
#include <bits/stdc++.h> using namespace std; #define task "test" #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define bit(s, i) (((s) >> (i)) & 1) #define ii pair <int, int> #define vii vector <ii> #define vi vector <int> #define fi first #define se second #define ll long long #define eb emplace_back #define pb push_back #define __builtin_popcount __builtin_popcountll void solve(); int32_t main() { if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int tc = 1; // cin >> tc; FOR(i, 1, tc) { solve(); } } const int N = 2e3+5; int s, n, dp[N]; vii item; void solve() { cin >> s >> n; FOR(i, 1, n) { int v, w, k; cin >> v >> w >> k; FOR(j, 0, 30) if(k >= (1<<j)) { k -= (1<<j); int nww = min(1<<j, s/w)*w, nwv = min(1<<j, s/w)*v; item.eb(nww, nwv); } item.eb(min(k,s/w)*w, min(k,s/w)*v); } for(auto [w, v]:item) { FORD(j, s, w) { dp[j] = max(dp[j], dp[j-w] + v); } } cout << dp[s]; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen(task".out", "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...