제출 #1047160

#제출 시각아이디문제언어결과실행 시간메모리
1047160SharkyKnapsack (NOI18_knapsack)C++17
100 / 100
76 ms36568 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2008; vector<pair<int, int>> val[N]; int dp[N][N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; for (int i = 1; i <= n; i++) { int v, w, k; cin >> v >> w >> k; if (w > s) continue; val[w].push_back({v, k}); } for (int i = 1; i <= s; i++) { sort(val[i].begin(), val[i].end(), [] (auto x, auto y) { return x.first > y.first; }); int threshold = s / i; vector<int> we; for (int j = 0; j < val[i].size(); j++) { int vv = val[i][j].first, sz = val[i][j].second; bool bad = 0; while (sz--) { if (we.size() >= threshold) { bad = 1; break; } we.push_back(vv); } if (bad) break; } for (int j = 0; j <= s; j++) dp[i][j] = dp[i - 1][j]; for (int j = s; j >= i; j--) { int cnt = 0; int ps = 0; for (auto x : we) { cnt++; ps += x; if (j >= cnt * i) dp[i][j] = max(dp[i][j], dp[i - 1][j - cnt * i] + ps); } } } int mx = 0; for (int j = 1; j <= s; j++) for (int i = 1; i <= s; i++) mx = max(mx, dp[j][i]); cout << mx << '\n'; return 0; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:26:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int j = 0; j < val[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~
knapsack.cpp:30:31: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   30 |                 if (we.size() >= threshold) {
      |                     ~~~~~~~~~~^~~~~~~~~~~~
#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...