제출 #1101116

#제출 시각아이디문제언어결과실행 시간메모리
1101116KindaGoodGamesKnapsack (NOI18_knapsack)C++14
100 / 100
85 ms8888 KiB
#include<bits/stdc++.h> #define ll long long #define int ll #define pii pair<int,int> #define tiii tuple<int,int,int> using namespace std; const ll INF = numeric_limits<ll>::max() / 2; int32_t main() { int s, n; cin >> s >> n; //vector<tiii> items(n); vector<vector<tiii>> itemsPerWeight(s + 1); for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; //items[i] = {v, w, k}; if (w <= s) itemsPerWeight[w].push_back({ v, w, k }); } vector<int> dp(s + 1, -INF); dp[0] = 0; // iterate through each block for (int i = 1; i <= s; i++) { // generate the block for this weight priority_queue<pii> pq; for (auto p : itemsPerWeight[i]) { pq.push({ get<0>(p), get<2>(p) }); } vector<int> values; values.push_back(0); for (int k = 1; k <= s / i; k++) { if (pq.empty()) break; auto p = pq.top(); pq.pop(); values.push_back(values[k - 1] + p.first); if (p.second > 1) pq.push({ p.first,p.second-1 }); } // do dp transitions for (int k = s; k > 0; k--) { for (int j = 0; j < values.size(); j++) { if (k - (j * i) < 0) break; dp[k] = max(dp[k], dp[k - (j * i)] + values[j]); } } } int ma = 0; for (int i = 0; i <= s; i++) { ma = max(ma, dp[i]); } cout << ma << endl; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:45:31: 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]
   45 |             for (int j = 0; j < values.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...