제출 #698887

#제출 시각아이디문제언어결과실행 시간메모리
698887CaubethieunangKnapsack (NOI18_knapsack)C++14
100 / 100
59 ms4960 KiB
/// (*^_^*) Author : Cau_be_thieu_nang #include <bits/stdc++.h> #define ll long long #define LOG 20 #define MASK(i) (1LL<<(i)) #define BIT(x,i) (((x)>>(i))&1) #define FIRST_BIT(mask) __builtin_ctz((mask)&(-mask)) #define ERASE_BIT(mask) (mask)^((mask)&(-mask)) #define left _left #define right _right #define task "t" using namespace std; const ll INF=1e18; const int iat=1e6+9; const int mod=1e9+7; void fast_IO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } } int s,n; vector <pair<ll,ll>> store[2001]; ll dp[2001]; signed main() { fast_IO(); cin>>s>>n; for(int i=1; i<=n; i++) { int v,w,k; cin>>v>>w>>k; store[w].push_back({v,k}); } for(int weight=0; weight<=s; weight++) { if(store[weight].empty())continue; sort(store[weight].begin(),store[weight].end(),greater<pair<ll,ll>>()); int pos=0; for(int i=0; weight*i<s; i++) { if(pos>=store[weight].size())break; for(int lim=s; lim>=weight; lim--)dp[lim]=max(dp[lim],dp[lim-weight]+store[weight][pos].first); store[weight][pos].second--; if(!store[weight][pos].second)pos++; } } cout<<dp[s]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:49:19: 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]
   49 |             if(pos>=store[weight].size())break;
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp: In function 'void fast_IO()':
knapsack.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(task".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...