제출 #1086680

#제출 시각아이디문제언어결과실행 시간메모리
1086680ntminKnapsack (NOI18_knapsack)C++14
100 / 100
79 ms34300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; #define all(x) x.begin(), x.end() #define ON(a, b) (a >> b & 1) template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;} template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;} const int N = 2001; int s, n; vector<pair<ll, int>> weight[N]; ll dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; for(int i = 1, v, w, k; i <= n; ++i){ cin >> v >> w >> k; weight[w].push_back({v, k}); } for(int i = 1; i <= s; ++i) sort(all(weight[i]), greater<pair<ll, int>>()); for(int i = 1; i <= s; ++i){ for(int j = 1; j <= s; ++j){ int cur = 0, id = 0, cnt = 0; ll val = 0; maximise(dp[i][j], dp[i - 1][j]); for(int t = i; t <= j; t += i){ while(id < (int)weight[i].size() && cur < t){ if(cnt >= weight[i][id].second){ cnt = 0; id++; } cnt++; cur += i; val += weight[i][id].first; } if(id >= weight[i].size()) break; maximise(dp[i][j], dp[i - 1][j - t] + val); } } } ll ans = 0; for(int i = 1; i <= s; ++i) maximise(ans, dp[s][i]); cout << ans; return 0; }

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

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