Submission #917420

#TimeUsernameProblemLanguageResultExecution timeMemory
917420PieArmyKnapsack (NOI18_knapsack)C++17
73 / 100
214 ms262144 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n'; #define int ll typedef long long ll; const ll inf=2000000000000000005; using namespace std; ll pie(ll army){return (1ll<<army);} ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} void code(){ int k,n;cin>>k>>n; int v[n],w[n],cnt[n]; for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>cnt[i]; vector<vector<int>>dp(n+1,vector<int>(k+1,0)); for(int i=0;i<n;i++){ for(int j=0;j<=k;j++){ for(int l=0;l<=cnt[i];l++){ if(j+(l*w[i])>k)break; dp[i+1][j+(l*w[i])]=max(dp[i+1][j+(l*w[i])],dp[i][j]+(l*v[i])); } } } int ans=0; for(int i=0;i<=k;i++)ans=max(ans,dp[n][i]); cout<<ans; } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:33:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:33:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".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...