Submission #471050

#TimeUsernameProblemLanguageResultExecution timeMemory
471050EvangKnapsack (NOI18_knapsack)C++17
17 / 100
2 ms320 KiB
#include "bits/extc++.h" #define int ll using namespace std; #ifdef LOCAL #define dout(x) clog << "Line " << __LINE__ << ": " << #x << "=" << (x) << el #else #define dout(x) #endif #define inf 1000000000 #define llinf 1000000000000000000ll #define uset unordered_set #define umap unordered_map #define mp(a,b) make_pair(a,b) #define mt(x...) make_tuple(x) #define eb(x...) emplace_back(x) #define pb(x) push_back(x) #define ff first #define ss second const char el = '\n', sp = ' '; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>; const int S = 2005; int s, n, dp[S]; void fun(int a, int c){ for(int i = s; i >= c; --i) dp[i] = max(dp[i], dp[i-c] + a); } int32_t main() { cin.tie(nullptr)->sync_with_stdio(false); #ifdef LOCAL freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif cin >> s >> n; while(n--){ int a, c, k; cin >> a >> c >> k; // while(k--) { // fun(a, c); // } int b[35] = {0}; for(int i = 0; k > 0; ++i) { b[i] = k&1; k/=2; } for(int i = 1; i < 35; ++i) if(b[i]&&!b[i-1]){ b[i] = 0; int j; for(j = i-1; j >= 0; --j){ if(j==0||b[j-1]) b[j] = 2; else b[j] = 1; } } for(int& i : b) { if(c>s) break; while (i--) fun(a, c); a *= 2; c *= 2; } } cout << dp[s]; }
#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...