제출 #1039211

#제출 시각아이디문제언어결과실행 시간메모리
1039211DeathIsAweKnapsack (NOI18_knapsack)C++14
0 / 100
9 ms13144 KiB
#include <bits/stdc++.h> using namespace std; int dp[2001][2001]; #define int long long int32_t main() { int s, n, d1, d2, d3; cin >> s >> n; vector<vector<pair<int,int>>> unsorted(2001); vector<vector<int>> items(2001); for (int i=0;i<n;i++) { cin >> d1 >> d2 >> d3; unsorted[d2].push_back(make_pair(d1,d3)); } for (int i=1;i<2001;i++) { items[i].push_back(0); sort(unsorted[i].begin(), unsorted[i].end(), greater<pair<int,int>>()); for (pair<int,int> j: unsorted[i]) { if (items[i].size() > 2000) { break; } if (items[i].size() + j.second > 2001) { for (int k=items[i].size();k<2001;k++) { items[i].push_back(items[i].back() + j.first); } } else { for (int k=0;k<j.second;k++) { items[i].push_back(items[i].back() + j.first); } } } } //for (int i=0;i<2001;i++) { // if (items[i].size() > 0) { // cout << i << ':'; // for (int j: items[i]) { // cout << j << ' '; // } // cout << '\n'; // } //} for (int i=0;i<2001;i++) { dp[0][i] = 0; dp[i][0] = 0; } for (int i=1;i<s+1;i++) { for (int j=1;j<2001;j++) { d2 = dp[i][j-1]; d1 = 0; while (d1 < items[j].size() && (d1 + 1) * j <= i) { d2 = max(d2, dp[i - ((d1 + 1) * j)][j-1] + items[j][d1]); d1++; } dp[i][j] = d2; } } cout << dp[s][2000]; }

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

knapsack.cpp: In function 'int32_t main()':
knapsack.cpp:52:27: 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]
   52 |                 while (d1 < items[j].size() && (d1 + 1) * j <= i) {
      |                        ~~~^~~~~~~~~~~~~~~~~
#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...