Submission #683639

#TimeUsernameProblemLanguageResultExecution timeMemory
683639vjudge1Knapsack (NOI18_knapsack)C++17
73 / 100
1064 ms17144 KiB
#include <bits/stdc++.h> using namespace std; #define task "a" #define etr "\n" #define ll long long #define ld long double #define pii pair<int,int> #define pli pair<long long,int> #define pll pair<long long, long long> #define fi first #define se second #define bg begin #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define lwb lower_bound #define upb upper_bound #define range(x, l, r) x+l, x+1+r #define all(x) (x).bg(), (x).end() #define compact(x) x.resize(unique(all(x)) - (x).bg()) #define sq(x) ((x)*(x)) void freop() { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } const int N=1e5, M=2e3, mod=1e9+7; int n, s; ll v[N*10+5], w[N*10+5], dp[M+5]; void process() { cin >> s >> n; for (int i=1; i<=n; i++) { ll k; cin >> v[i] >> w[i]; cin >> k; k = min(k, s/w[i]); int bit = 0; while (true) { if (k >= (1 << bit)) { v[i+bit] = v[i] * (1 << bit); w[i+bit] = w[i] * (1 << bit); k -= (1 << bit); if (k == 0) break; } else { v[i+bit] = v[i] * k; w[i+bit] = w[i] * k; break; } bit++; } i += bit; n += bit; } ll res=0; for (int i=1; i<=n; i++) { for (int j=s; j>=w[i]; j--) { dp[j] = max(dp[j], dp[j-w[i]] + v[i]); res = max(res, dp[j]); } } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t=1; //cin >> t; while (t--) process(); return 0; }

Compilation message (stderr)

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