제출 #973962

#제출 시각아이디문제언어결과실행 시간메모리
973962vjudge1Knapsack (NOI18_knapsack)C++17
100 / 100
657 ms162020 KiB
#include<bits/stdc++.h> using namespace std; const int MAXS = 2000; const int MAXITEM = 20000; const int INF = 2e9; int S, N; vector<pair<int, int> > A[MAXS + 5]; vector<pair<int, int> > items; int DP[MAXITEM + 5][MAXS + 5]; int f(int idx, int cap) { if (cap < 0) return -INF; if (idx == items.size()) return 0; int &ret = DP[idx][cap]; if (ret != -1) return ret; auto [w, v] = items[idx]; return ret = max(f(idx + 1, cap), f(idx + 1, cap - w) + v); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> S >> N; for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; A[w].push_back({v, k}); } for (int w = 1; w <= MAXS; w++) { sort(A[w].begin(), A[w].end()); int used = MAXS / w + 1; while (used != 0 && !A[w].empty()) { auto &[v, k] = A[w].back(); items.push_back({w, v}); k--; used--; if (k == 0) A[w].pop_back(); } } memset(DP, -1, sizeof DP); cout << f(0, S) << endl; return 0; }

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

knapsack.cpp: In function 'int f(int, int)':
knapsack.cpp:15:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     if (idx == items.size()) return 0;
      |         ~~~~^~~~~~~~~~~~~~~
#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...