Submission #1003102

#TimeUsernameProblemLanguageResultExecution timeMemory
1003102fryingducKnapsack (NOI18_knapsack)C++17
73 / 100
1095 ms17548 KiB
// #pragma GCC optimize("Ofast,unroll-loops") #include "bits/stdc++.h" using namespace std; #define int long long #define sz(a) ((int)(a).size()) #define all(a) (a).begin(), (a).end() #define yes cout << "YES\n" #define no cout << "NO\n" #ifdef LOCAL #define debug(val) cerr << "["#val << " = " << (val) << "] " #define slash() cerr << "\n-----------\n" #define time() cerr << "Time is: " << 1000 * clock()/CLOCKS_PER_SEC << " ms\n" #else #define debug(val) 1407 #define slash() 1407 #define time() 1407 #endif const string filename = ""; void IO(){ ios_base::sync_with_stdio(0); cin.tie(0); if(filename.size()){ string in = filename + ".inp"; string out = filename + ".out"; freopen(in.c_str(), "r", stdin); freopen(out.c_str(), "w", stdout); } } int n, W; vector<int> v, w; void solve(){ cin >> W >> n; for(int i=0;i<n;i++){ int a, b, c; cin >> b >> a >> c; int bits=1; while(c - bits >= 0){ v.push_back(b * bits); w.push_back(a * bits); c -= bits; bits *= 2; } if(c){ v.push_back(c * b); w.push_back(c * a); } } vector<int> dp(W+1); for(int i=0;i<v.size();i++){ for(int j=W;j>=w[i];j--){ if(j - w[i] >= 0) dp[j] = max(dp[j], dp[j-w[i]] + v[i]); } } cout << dp[W]; } signed main(){ IO(); int test = 1; /* cin >> test; */ for(int i=1;i<=test;i++){ // cout << "Case " << "#" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:54:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
knapsack.cpp: In function 'void IO()':
knapsack.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(in.c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(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...