QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795953#9806. Growing Treeucup-team4435#Compile Error//C++233.4kb2024-12-01 05:04:032024-12-01 05:04:03

Judging History

你现在查看的是最新测评结果

  • [2024-12-01 05:04:03]
  • 评测
  • [2024-12-01 05:04:03]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("popcnt")

#include "bits/stdc++.h"


#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const int INFi = 2e9;
const ll INF = 2e18;

using Bitset = bitset<1005>;

void solve() {
    int n; cin >> n;
    vl a(1 << (n + 1));
    for(int i = 2; i < a.size(); ++i) {
        cin >> a[i];
//        cerr << "READ" << endl;
        a[i] += a[i / 2];
    }

    vector<ll> xx;
    for(int i = (1 << n); i < a.size(); ++i) {
        xx.push_back(a[i]);
    }
    sort(all(xx));

    vector<vector<Bitset>> b(1 << n);
    for(int i = (1 << n); i < a.size(); ++i) {
        Bitset cur = 0;
        int x = lower_bound(all(xx), a[i]) - xx.begin();
        cur[x] = 1;
        b[i - (1 << n)].push_back(cur);
    }

    int use = n;
    for(int lvl = n; lvl >= 1; --lvl) {
        vector<vector<Bitset>> b2(1 << (lvl - 1));
        for(int i = (1 << (lvl - 1)); i < (1 << lvl); ++i) {
            int x = i * 2;
            int y = i * 2 + 1;
            x -= (1 << lvl);
            y -= (1 << lvl);
            int to =  i - (1 << (lvl - 1));

            vector<Bitset> zero, one;
            for(auto &c1 : b[x]) {
                for(auto &c2 : b[y]) {
                    if ((c1 & c2).count()) {
                        continue;
                    }
                    zero.push_back(c1 | c2);
                }
            }
            if (!zero.empty()) {
                b2[to] = zero;
            } else {
                if (use < lvl) {
                    cout << "-1\n";
                    return;
                }
                use--;
                b2[to] = b[x];
                for(auto &c : b[y]) b2[to].push_back(c);
            }
        }
        swap(b, b2);
    }
    cout << n - use << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
    cin >> t;

    rep(i, t) {
        solve();
    }
    return 0;
}

詳細信息

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 answer.code:4:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<long long int, std::allocator<long long int> >::_Vector_impl::~_Vector_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 = long long int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~