Submission #508876

#TimeUsernameProblemLanguageResultExecution timeMemory
508876hqbKnapsack (NOI18_knapsack)C++14
73 / 100
1075 ms17352 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ar array const int maxN = 2e3 + 1, INF = 1e9, MOD = 1e9 + 7; ll M,N,dp[maxN]; vector<ll> v,w; void setIO(string name=""){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } int main(){ cin.tie(0); cin.sync_with_stdio(0); //setIO(); cin >> M >> N; for (int i=0;i<N;i++){ ll a,b,c; cin >> a >> b >> c; for (ll p=1;c-p>=0;c-=p,p*=2){ v.push_back(p*a),w.push_back(p*b); } if (c>0) v.push_back(c*a),w.push_back(c*b); } for (int i=0;i<v.size();i++){ for (int j=M;j>=w[i];j--){ dp[j] = max(dp[j],dp[j-w[i]]+v[i]); } } cout << dp[M] << '\n'; return 0; }

Compilation message (stderr)

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