Submission #1330009

#TimeUsernameProblemLanguageResultExecution timeMemory
1330009pucam20102Knapsack (NOI18_knapsack)C++20
Compilation error
0 ms0 KiB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;

static long long dp[100005];
static long long olddp[100005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int S, N;
    cin >> S >> N;

    for(int i = 0; i <= S; i++)
        dp[i] = 0;

    while(N--) {
        long long V, W, K;
        cin >> V >> W >> K;

        for(int i = 0; i <= S; i++)
            olddp[i] = dp[i];

        for(int r = 0; r < W; r++) {
            deque<pair<long long,int>> dq;

            for(int k = 0; r + k*W <= S; k++) {
                int idx = r + k*W;
                long long val = olddp[idx] - k * V;

                while(!dq.empty() && dq.back().first <= val)
                    dq.pop_back();

                dq.emplace_back(val, k);

                while(!dq.empty() && dq.front().second < k - K)
                    dq.pop_front();

                dp[idx] = dq.front().first + k * V;
            }
        }
    }

    cout << dp[S] << "\n";
    return 0;
}

Compilation message (stderr)

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from knapsack.cpp:4:
/usr/include/c++/13/bits/allocator.h: In destructor 'constexpr std::_Deque_base<std::pair<long long int, int>, std::allocator<std::pair<long long int, int> > >::_Deque_impl::~_Deque_impl()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<long long int, int>]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:139:
/usr/include/c++/13/bits/stl_deque.h:542:14: note: called from here
  542 |       struct _Deque_impl
      |              ^~~~~~~~~~~