제출 #849066

#제출 시각아이디문제언어결과실행 시간메모리
849066AbdalrhmanMohammadKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define ll long long #define yn(tf) cout << (tf ? "YES\n" : "NO\n") #define Endl endl #define ld long double const ld PI = 3.14159265359; const ll MOD = 998244353; const ll N = 1e5 + 7; int s, n; int v[N], w[N], k[N]; vector<vector<int>> mem; int fun(int i, int rem) { if (rem < 0) return -1e9; if (i == n || rem == 0) return 0; int &res = mem[i][rem]; if (res != -1) return res; res = fun(i + 1, rem); for (ll j = 1; j <= min(2000, k[i]); j++) res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j); return res; } int main() { FAST cin >> s >> n; mem = vector<vector<ll>>(n + 1, vector<ll>(s + 1)); for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for (int i = 0; i <= n; i++) for (int j = 0; j <= s; j++) mem[i][j] = -1; cout << fun(0, s); return 0; } /* */ // BEFORE coding are you sure you understood the statement correctly? // PLEASE do not forget to read the sample explanation carefully. // WATCH out for overflows & RTs in general. // TEST your idea or code on the corner cases. // ANALYZE each idea you have thoroughly. Compilation message

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

knapsack.cpp: In function 'int fun(int, int)':
knapsack.cpp:31:57: error: no matching function for call to 'max(int&, long long int)'
   31 |     res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j);
      |                                                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
knapsack.cpp:31:57: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   31 |     res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j);
      |                                                         ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
knapsack.cpp:31:57: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   31 |     res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j);
      |                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
knapsack.cpp:31:57: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |     res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j);
      |                                                         ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
knapsack.cpp:31:57: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |     res = max(res, fun(i + 1, rem - j * w[i]) + v[i] * j);
      |                                                         ^
knapsack.cpp: In function 'int main()':
knapsack.cpp:38:52: error: no match for 'operator=' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<std::vector<long long int> >')
   38 |   mem = vector<vector<ll>>(n + 1, vector<ll>(s + 1));
      |                                                    ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<std::vector<long long int> >' to 'const std::vector<std::vector<int> >&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from knapsack.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<std::vector<long long int> >' to 'std::vector<std::vector<int> >&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<std::vector<long long int> >' to 'std::initializer_list<std::vector<int> >'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
knapsack.cpp: At global scope:
knapsack.cpp:58:1: error: 'Compilation' does not name a type
   58 | Compilation message
      | ^~~~~~~~~~~