답안 #976445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976445 2024-05-06T14:58:58 Z vjudge1 Knapsack (NOI18_knapsack) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))
#define pow2(x) ((ll)(x) * (x))
const ll mod = 1e9 + 7;
const int INF = 1e9 + 5; // 998244353
const ll INFF = 1e18 + 5;
// Super is the cutest girl
void solve()
{
    int s, n;
    cin >> s >> n;
    vector<pii> byweight[s + 1];

    for (int i = 0; i < n; i++)
    {
        int v, w, k;
        cin >> v >> w >> k;
        byweight[w].pb({v, k});
    }
    vector<pii> items;
    for (int w = 1; w <= s; w++)
    {
        sort(all(byweight[w]));
        int used = s / w + 1;

        while (used != 0 && !byweight[w].empty())
        {
            auto &[v, k] = byweight[w].back();
            items.pb({w, v});
            k--;
            used--;
            if (k == 0)
                byweight[w].pop_back();
        }
    }
    int sz = items.size();
    int dp[sz + 1][s + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= sz; i++)
    {

        for (int w = s; w >= 0; w--)
        {
            dp[i][w] = max(dp[i][w], dp[i - 1][w]);
            if (w - items[i - 1].first >= 0)
            {
                dp[i][w - items[i - 1].first] = max(dp[i][w - items[i - 1].first], dp[i - 1][w] + items[i - 1].second);
            }
        }
    }
    ll ans = 0;
    for (auto i : dp[sz])
    {
        ans = max(ans, i);
    }
    cout << ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // int t; cin >> t; while(t--)
    solve();
}

Compilation message

knapsack.cpp: In function 'void solve()':
knapsack.cpp:40:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |             auto &[v, k] = byweight[w].back();
      |                   ^
knapsack.cpp:66:25: error: no matching function for call to 'max(ll&, int&)'
   66 |         ans = max(ans, i);
      |                         ^
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> 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:66:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |         ans = max(ans, i);
      |                         ^
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> 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:66:25: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |         ans = max(ans, i);
      |                         ^
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> _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:66:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   66 |         ans = max(ans, i);
      |                         ^
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> _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:66:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   66 |         ans = max(ans, i);
      |                         ^