제출 #1090110

#제출 시각아이디문제언어결과실행 시간메모리
1090110StaheosKnapsack (NOI18_knapsack)C++14
100 / 100
26 ms1860 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, s; cin >> s >> n; //auto q = new priority_queue<pair<int, int>>[s + 1]; priority_queue<pair<int, int>> q[s + 1]; for (int i = 0; i <= s; i++) { q[i] = priority_queue<pair<int, int>>(); } for (int i = 0; i < n; i++) { int v, w, k; cin >> v >> w >> k; q[w].push(pair<int, int>(v, k)); } auto e = new vector<long long>[s + 1]; for (int i = 0; i <= s; i++) { e[i] = vector<long long>(); while (!q[i].empty() && e[i].size() < s && e[i].size() * i < s) //while (!q[i].empty() && e[i].size() < s) { auto p = q[i].top(); q[i].pop(); e[i].push_back(p.first); p.second--; if (p.second > 0) { q[i].push(p); } } } //delete[] q; long long* dp = new long long[s + 1]; for (int i = 1; i <= s; i++) { dp[i] = -1; } dp[0] = 0; for (int i = 1; i <= s; i++) { if (e[i].size() < 1) { continue; } for (int j = s; j >= 0; j--) { if (dp[j] == -1) { continue; } for (int k = 0; k < e[i].size() && j + i * (k + 1) <= s; k++) //for (int k = 0; k < e[i].size() && j + i * (k + 1) <= s && i * k <= s; k++) { if (dp[j + i * (k + 1)] == -1) { dp[j + i * (k + 1)] = dp[j + i * k] + e[i][k]; } else if (dp[j + i * (k + 1)] < dp[j + i * k] + e[i][k]) { dp[j + i * (k + 1)] = dp[j + i * k] + e[i][k]; } else { break; } } } } int m = 0; for (int i = 0; i <= s; i++) { //cout << "dp " << i << ' ' << dp[i] << '\n'; if (dp[i] > dp[m]) { m = i; } } cout << dp[m]; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:32:39: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |   while (!q[i].empty() && e[i].size() < s && e[i].size() * i < s)
      |                           ~~~~~~~~~~~~^~~
knapsack.cpp:32:62: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |   while (!q[i].empty() && e[i].size() < s && e[i].size() * i < s)
      |                                              ~~~~~~~~~~~~~~~~^~~
knapsack.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    for (int k = 0; k < e[i].size() && j + i * (k + 1) <= s; k++)
      |                    ~~^~~~~~~~~~~~~
#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...