제출 #959830

#제출 시각아이디문제언어결과실행 시간메모리
959830susanthenerdKnapsack (NOI18_knapsack)C++98
컴파일 에러
0 ms0 KiB
#include <iostream> #include <algorithm> #include <map> #include <vector> #include <climits> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int s, n, m = 0; cin >> s >> n; vector v(s + 1, vector<pair<int, int>>()); for (int i = 0; i < n; ++i) { int pret, greu, cnt; cin >> pret >> greu >> cnt; if (greu <= s && cnt > 0) { if (v[greu].empty()) ++m; v[greu].emplace_back(pret, cnt); } } vector dp(m + 1, vector<ll>(s + 1, LLONG_MIN)); dp[0][0] = 0; for (int a = 0, i = 0; a <= s; ++a) { if (!v[a].empty()) { ++i; sort(v[a].begin(), v[a].end(), greater<>()); for (int j = 0; j <= s; ++j) { dp[i][j] = dp[i - 1][j]; int cnt = 0, tip = 0, used = 0; ll profit = 0; while ((cnt + 1) * a <= j && tip < v[a].size()) { ++cnt; profit += v[a][tip].first; if (dp[i - 1][j - cnt * a] != LLONG_MIN) dp[i][j] = max(dp[i][j], dp[i - 1][j - cnt * a] + profit); ++used; if (used == v[a][tip].second) { used = 0; ++tip; } } } } } cout << *max_element(dp.back().begin(), dp.back().end()) << '\n'; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:18:12: error: missing template arguments before 'v'
   18 |     vector v(s + 1, vector<pair<int, int>>());
      |            ^
knapsack.cpp:25:17: error: 'v' was not declared in this scope
   25 |             if (v[greu].empty())
      |                 ^
knapsack.cpp:27:13: error: 'v' was not declared in this scope
   27 |             v[greu].emplace_back(pret, cnt);
      |             ^
knapsack.cpp:31:12: error: missing template arguments before 'dp'
   31 |     vector dp(m + 1, vector<ll>(s + 1, LLONG_MIN));
      |            ^~
knapsack.cpp:32:5: error: 'dp' was not declared in this scope
   32 |     dp[0][0] = 0;
      |     ^~
knapsack.cpp:35:14: error: 'v' was not declared in this scope
   35 |         if (!v[a].empty()) {
      |              ^