제출 #586822

#제출 시각아이디문제언어결과실행 시간메모리
586822krit3379Knapsack (NOI18_knapsack)C++17
29 / 100
2 ms340 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define N 2005 long long dp[N],ans; vector<pair<int,int>> g[N],op; int main(){ int n,s,i,v,w,k,cnt; scanf("%d %d",&s,&n); for(i=1;i<=n;i++){ scanf("%d %d %d",&v,&w,&k); g[w].push_back({v,k}); } for(i=1;i<=s;i++)sort(g[i].begin(),g[i].end(),greater<pair<int,int>>()); for(i=1;i<=s;i++){ cnt=0; for(auto [v,k]:g[i]){ if(cnt+k<=s)while(k--)op.push_back({v,i}),cnt+=k; else{ k=s-cnt; cnt=s; while(k--)op.push_back({v,i}); } if(cnt==s)break; } } for(auto [v,w]:op)for(i=s;i>=w;i--)dp[i]=max(dp[i],dp[i-w]+v); for(i=0;i<=s;i++)ans=max(ans,dp[i]); printf("%lld",ans); return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&s,&n);
      |     ~~~~~^~~~~~~~~~~~~~~
knapsack.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%d %d %d",&v,&w,&k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...