제출 #652329

#제출 시각아이디문제언어결과실행 시간메모리
652329lamKnapsack (NOI18_knapsack)C++14
100 / 100
116 ms62256 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int maxn = 1e6 + 10; typedef pair<int,int> ii; #define ff first #define ss second int s,n; int v[maxn],w[maxn],k[maxn]; vector <ii> a[maxn]; int dp[2010][2010]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>s>>n; for (int i=1; i<=n; i++) { cin>>v[i]>>w[i]>>k[i]; a[w[i]].push_back({v[i],k[i]}); } for (int i=1; i<=s; i++) { sort(a[i].begin(),a[i].end(),greater<ii>()); for (int j=1; j<=s; j++) { dp[i][j]=dp[i-1][j]; if (a[i].empty()) continue; int it,cnt,used,val; it=cnt=val=0; used=a[i][it].ss; while (it<(int)(a[i].size()) && (cnt+1)*i <=j ) { used--; cnt++; val+=a[i][it].ff; dp[i][j]=max(dp[i][j],dp[i-1][j-cnt*i]+val); if (used==0) { it++; if (it<a[i].size()) used=a[i][it].ss; } } } } int ans=0; for (int i=1; i<=s; i++) ans=max(ans,dp[s][i]); cout<<ans; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:41:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |                     if (it<a[i].size()) used=a[i][it].ss;
      |                         ~~^~~~~~~~~~~~
knapsack.cpp:47:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   47 |     for (int i=1; i<=s; i++) ans=max(ans,dp[s][i]); cout<<ans;
      |     ^~~
knapsack.cpp:47:53: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   47 |     for (int i=1; i<=s; i++) ans=max(ans,dp[s][i]); cout<<ans;
      |                                                     ^~~~
#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...