제출 #917438

#제출 시각아이디문제언어결과실행 시간메모리
917438PieArmyKnapsack (NOI18_knapsack)C++17
29 / 100
1 ms500 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n'; 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<int>dp(k+1,0); vector<pair<int,int>>ek(k+1,make_pair(-1,0)); for(int i=0;i<n;i++){ vector<int>dp2(k+1,0); vector<pair<int,int>>ek2(k+1,make_pair(-1,0)); for(int j=0;j<=k;j++){ dp2[j]=max(dp2[j],max(dp[j],ek[j].fr)); if(j+w[i]<=k){ if(dp[j]>=ek[j].fr){ ek[j+w[i]]={dp[j]+v[i],cnt[i]-1}; } else{ if(ek[j].sc){ ek[j+w[i]]={ek[j].fr+v[i],ek[j].sc-1}; } if(j+(ek[j].sc*w[i])+w[i]<=k){ ek[j+(ek[j].sc*w[i])+w[i]]={dp[j]+(ek[j].sc*v[i])+v[i],cnt[i]-ek[j].sc-1}; } } } } swap(dp,dp2); } int ans=0; for(int i=0;i<=k;i++)ans=max(ans,dp[i]); cout<<ans; } int 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; }

컴파일 시 표준 에러 (stderr) 메시지

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