제출 #1048873

#제출 시각아이디문제언어결과실행 시간메모리
1048873tamir1Knapsack (NOI18_knapsack)C++17
100 / 100
72 ms5088 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll n,S,i,j,l,res,dp[2005],s,w,k; vector<ll> v[2001]; vector<pair<ll,ll>> t[2001]; bool cmp(pair<ll,ll> a,pair<ll,ll> b){ return a.first>b.first; } int main(){ cin >> S >> n; for(i=1;i<=n;i++){ cin >> s >> w >> k; t[w].push_back({s,k}); } for(i=1;i<=S;i++){ sort(t[i].begin(),t[i].end(),cmp); ll mx=S/i; for(j=0;j<t[i].size();j++){ s=t[i][j].first; k=t[i][j].second; if(mx<=k){ for(l=1;l<=mx;l++) v[i].push_back(s); break; } else{ for(l=1;l<=k;l++) v[i].push_back(s); mx-=k; } } for(j=1;j<v[i].size();j++) v[i][j]+=v[i][j-1]; } for(i=1;i<=S;i++){ for(l=S;l>=i;l--){ for(j=0;j<v[i].size();j++){ if(l-i*(j+1)<0) break; dp[l]=max(dp[l],dp[l-i*(j+1)]+v[i][j]); } } } for(i=0;i<=S;i++) res=max(res,dp[i]); cout << res; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:19:12: 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]
   19 |   for(j=0;j<t[i].size();j++){
      |           ~^~~~~~~~~~~~
knapsack.cpp:31:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(j=1;j<v[i].size();j++) v[i][j]+=v[i][j-1];
      |           ~^~~~~~~~~~~~
knapsack.cpp:35:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for(j=0;j<v[i].size();j++){
      |            ~^~~~~~~~~~~~
#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...