제출 #1090011

#제출 시각아이디문제언어결과실행 시간메모리
1090011EmmaXIIKnapsack (NOI18_knapsack)C++17
100 / 100
471 ms7440 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; using vi = vector<int>; using vvi = vector<vector<int>>; using vll = vector<ll>; using vvll = vector<vector<ll>>; #define all(x) x.begin(), x.end() #define ckmin(a,b) a = min(a,b) #define ckmax(a,b) a = max(a,b) int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); int N, S; cin >> S >> N; vll V(N); vi W(N); vll K(N); for (int i=0;i<N;i++) cin >> V[i] >> W[i] >> K[i]; vector<vector<pair<ll,ll>>> items_by_weight(S+1); for (int i=0;i<N;i++) { items_by_weight[W[i]].push_back({V[i], K[i]}); } vector<tuple<ll, int, ll>> items; for (int i=1;i<=S;i++) { sort(all(items_by_weight[i])); reverse(all(items_by_weight[i])); for (int j=0;j < items_by_weight[i].size() && j*i<=S;j++) { auto [v, k] = items_by_weight[i][j]; items.push_back({i, v, k}); } } vll dp(S+1, 0); for (auto [w, v, k] : items) { vll ndp(S+1, 0); for (int j=0;j<=w && j<=S;j++) { priority_queue<pair<ll, int>> maxes; for (int jp=0;j+jp*w<=S;jp++) { maxes.push({dp[j + jp*w] - jp*v, jp}); while(maxes.top().second < jp - k) maxes.pop(); ll curmax = maxes.top().first; ckmax(ndp[j+jp*w], curmax + jp*v); } } swap(ndp, dp); } cout << dp[S] << endl; return 0; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:37:24: 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 j=0;j < items_by_weight[i].size() && j*i<=S;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...