Submission #1040366

#TimeUsernameProblemLanguageResultExecution timeMemory
1040366RequiemKnapsack (NOI18_knapsack)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "knapsack" using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 100009; int s[MAXN],w[MAXN],k[MAXN],dp[2009][2009]; int n,S; vector<int> value[2009]; struct data{ int s,w,k; }; data d[MAXN]; bool cmp(data a,data b){ if (a.s!=b.s) return (a.s < b.s); else return (a.w < b.w); } main() { fast; // freopen(TASKNAME".inp","r",stdin); // freopen(TASKNAME".out","w",stdout); cin>>S>>n; for(int i=1;i<=n;i++){ cin>>d[i].s>>d[i].w>>d[i].k; } sort(d+1,d+1+n,cmp); for(int i=n;i>=1;i--){ int w = d[i].w; if (value[w].size() < S/w){ for(int t=1;t<=d[i].k;t++){ value[w].pb(d[i].s); if (value[w].size() == S/w) break; } } } for(int i=1;i<=S;i++){ for(int j=0;j<=S;j++){ dp[i][j] = dp[i-1][j]; int sum = 0,sz=value[i].size(); for(int t=1;t <= sz; t++){ sum += value[i][t-1]; if (j>=t*i) dp[i][j] = max(dp[i][j], dp[i-1][j-t*i] + sum); } } } cout<<dp[S][S]<<endl; }

Compilation message (stderr)

knapsack.cpp:26:1: error: reference to 'data' is ambiguous
   26 | data d[MAXN];
      | ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
knapsack.cpp:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
knapsack.cpp:27:10: error: reference to 'data' is ambiguous
   27 | bool cmp(data a,data b){
      |          ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
knapsack.cpp:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
knapsack.cpp:27:17: error: reference to 'data' is ambiguous
   27 | bool cmp(data a,data b){
      |                 ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 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/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
knapsack.cpp:23:8: note:                 'struct data'
   23 | struct data{
      |        ^~~~
knapsack.cpp:27:23: error: expression list treated as compound expression in initializer [-fpermissive]
   27 | bool cmp(data a,data b){
      |                       ^
knapsack.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main()
      | ^~~~
knapsack.cpp: In function 'int main()':
knapsack.cpp:38:14: error: 'd' was not declared in this scope
   38 |         cin>>d[i].s>>d[i].w>>d[i].k;
      |              ^
knapsack.cpp:40:10: error: 'd' was not declared in this scope
   40 |     sort(d+1,d+1+n,cmp);
      |          ^
knapsack.cpp:43:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   43 |         if (value[w].size() < S/w){
      |             ~~~~~~~~~~~~~~~~^~~~~
knapsack.cpp:46:37: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   46 |                 if (value[w].size() == S/w) break;
      |                     ~~~~~~~~~~~~~~~~^~~~~~