Submission #1225058

#TimeUsernameProblemLanguageResultExecution timeMemory
1225058bounce_29Knapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<long long> #define pb push_back #define endll "\n" #define vvll vector<vector<long long>> const int MOD = 1e9 + 7; #define rep(i, a , n) for (int i = a; i < (n); i++) #define nrep(i, n , a) for (int i = n-1; i >= (a); i--) void solve() { ll s, n; cin >> s >> n; vector<vector<pair<ll, ll>>> items(s+1); rep (i, 0, n) { ll value, weight, count; cin >> value >> weight >> count; if (weight > s) continue; items[weight].push_back({value, count}); } vector<pair<ll, ll>> all_items; rep (i, 1, s+1){ sort(items[i].begin(), items[i].end(), greater<pair<ll, ll>>()); ll accu_weight = 0; for (auto item: items[i]) { ll y = 1 ll value = item.first, count = item.second; while(1){ accu_weight += i * y; if (accu_weight > s) break; if (count == 0) break; if (y > count) y = count; all_items.pb({y*value, i * y}); count -= y; y*=2; } if (accu_weight > s) break; } } vector<ll> dp(s+1, 0); for (auto item: all_items) { ll value = item.first, weight = item.second; nrep (i, s+1, weight){ dp[i] = max(dp[i], dp[i - weight] + value); } } cout << dp[s] << endll; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }

Compilation message (stderr)

knapsack.cpp: In function 'void solve()':
knapsack.cpp:3:12: error: expected ',' or ';' before 'long'
    3 | #define ll long long
      |            ^~~~
knapsack.cpp:31:13: note: in expansion of macro 'll'
   31 |             ll value = item.first, count = item.second;
      |             ^~
knapsack.cpp:35:27: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator=='
   35 |                 if (count == 0) break;
      |                     ~~~~~~^~~~
knapsack.cpp:36:23: error: invalid operands of types 'long long int' and '<unresolved overloaded function type>' to binary 'operator>'
   36 |                 if (y > count) y = count;
      |                     ~~^~~~~~~
knapsack.cpp:36:36: error: cannot resolve overloaded function 'count' based on conversion to type 'long long int'
   36 |                 if (y > count) y = count;
      |                                    ^~~~~
knapsack.cpp:37:33: error: 'value' was not declared in this scope
   37 |                 all_items.pb({y*value, i * y});
      |                                 ^~~~~
knapsack.cpp:37:29: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
   37 |                 all_items.pb({y*value, i * y});
      |                 ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from /usr/include/c++/11/functional:62,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<long long int, long long int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
knapsack.cpp:38:26: error: overloaded function with no contextual type information
   38 |                 count -= y;
      |                          ^