제출 #1043771

#제출 시각아이디문제언어결과실행 시간메모리
1043771vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
50 ms2136 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pb push_back #define fi first #define se second #define debug(x) cerr << #x << " => " << x << endl #define all(x) x.begin(),x.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int s,n;cin>>s>>n; pair<int,pii> p[n]; for(int i=0;i<n;i++) cin>>p[i].se.fi>>p[i].fi>>p[i].se.se; sort(p,p+n,greater<pair<int,pii>>()); vector<pll> a; int now=s,cnt=0; for(int i=0;i<n;i++) { if(p[i].fi!=now) now=p[i].fi,cnt=0; while(cnt!=s/now && p[i].se.se!=0) { a.pb({p[i].fi,p[i].se.fi}); p[i].se.se--; cnt++; } } ll dp[2][s+1]; memset(dp,0,sizeof(dp)); for(int i=0;i<a.size();i++) { for(int j=0;j<=s;j++) { dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][j]); if(j+a[i].fi<=s) dp[i%2][j+a[i].fi]=max(dp[i%2][j+a[i].fi],dp[(i+1)%2][j]+a[i].se); } // for(int j=0;j<=s;j++) cout<<dp[i%2][j]<<' ';cout<<'\n'; } cout<<dp[(a.size()-1)%2][s]; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0;i<a.size();i++)
      |              ~^~~~~~~~~
#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...