/ SeriousOJ /

Record Detail

Compile Error

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from foo.cc:3:
/usr/include/c++/13/bits/allocator.h: In destructor 'std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/string:54:
/usr/include/c++/13/bits/basic_string.h:181:14: note: called from here
  181 |       struct _Alloc_hider : allocator_type // TODO check __is_final
      |              ^~~~~~~~~~~~

Code

#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#pragma GCC optimize("O2,O3,Ofast,inline,unroll-all-loops,-ffast-math")
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <random>
#include <tuple>
#include <numeric>
#include <map>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;

template <typename T, typename = void>
struct has_val_function : std::false_type {};

template <typename T>
struct has_val_function<T, std::void_t<decltype(std::declval<std::ostream&>() << std::declval<T>().val())>> : std::true_type { };

template<typename t>
typename std::enable_if_t<has_val_function<t>::value, std::ostream&>
operator << (ostream& o, const t &c)
{
    o << c.val() << " ";
    return o;
}

template<typename t, typename b>
ostream& operator << (ostream& o, const pair<t, b> &c)
{

    o << "(" << c.first <<"," << c.second << ") ";
    return o;
}


template<typename t, typename b, typename x>
ostream& operator << (ostream& o, const tuple<t, b, x> &c)
{

    o << "(" << std::get<0>(c) <<"," << std::get<1>(c) << "," << std::get<2>(c) << ") ";
    return o;
}

template<typename t>
typename std::enable_if_t<std::is_void<std::void_t<decltype(std::begin(std::declval<t>())), decltype(std::end(std::declval<t>()))>>::value, std::ostream&>
        operator << (ostream& o, const t &c)
{
    for(size_t i = 0; i < c.size(); i++)
    {
        o << c[i] << " ";
    }
    return o;
}
const int N = 2e5 + 5;

const string yes = "YES";
const string no = "NO";

int a[N][6];
int n, k;

int f[N][1 << 5];

int main()
{
#ifdef local
    freopen("in.txt", "r", stdin);
#endif // local
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j < k; j++)
        {
            cin >> a[i][j];
        }
        for(int j = 0; j < (1 << k); j++)
        {
            for(int x = 0; x < k; x++)
            {
                if (j >> x & 1)
                    f[i][j] += a[i][x];
                else f[i][j] -= a[i][x];
            }
        }
    }
    vector<set<pair<int, int>>> closed(1 << k), open(1 << k);

    auto insert = [](auto & vec_s, int id)
    {
        for(int i = 0; i < (1 << k); i++)
        {
            vec_s[i].insert({f[id][i], id});
        }
    };

    auto remove = [](auto & vec_s, int id)
    {
        for(int i = 0; i < (1 << k); i++)
        {
            vec_s[i].erase({f[id][i], id});
        }
    };
    vector<vector<pair<int, int>>> tmp(1 << k);
    for(int i = 1; i <= n; i++)
    {
        if (i == 1)
        {
            insert(closed, i);
        }
        else {
            for(int j = 0; j < (1 << k); j++) {
                tmp[j].push_back({f[i][j], i});
            }
        }
    }
    for(int j = 0; j < (1 << k); j++) {
        open[j] = set<pair<int, int>>(tmp[j].begin(), tmp[j].end());
    }
    ll ans = 0;
    for(int i = 1; i < n; i++)
    {
        int best = -1;
        int id = 0;
        for(int j = 0; j < (1 << k); j++)
        {
            auto minv = *closed[j].begin();
            auto maxv = *closed[j].rbegin();

            auto cminv = *open[j].begin();
            auto cmaxv = *open[j].rbegin();


            if (abs(minv.first - cmaxv.first) >= best)
            {
                best = abs(minv.first - cmaxv.first);
                id = cmaxv.second;
            }

            if (abs(minv.first - cminv.first) >= best)
            {
                best = abs(minv.first - cminv.first);
                id = cminv.second;
            }

            if (abs(maxv.first - cminv.first) >= best)
            {
                best = abs(maxv.first - cminv.first);
                id = cminv.second;
            }

            if (abs(maxv.first - cmaxv.first) >= best)
            {
                best = abs(maxv.first - cmaxv.first);
                id = cmaxv.second;
            }
        }
        ans += best;
        insert(closed, id);
        remove(open, id);
    }
    cout << ans << endl;
}

Information

Submit By
Type
Submission
Problem
P1098 KuZ the Maximum spanning tree
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 11:15:03
Judged At
2024-12-10 11:15:03
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes