QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125381#91. Secret PermutationQwerty1232#Compile Error//C++202.8kb2023-07-16 16:31:462024-07-04 00:44:08

Judging History

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

  • [2024-07-04 00:44:08]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 16:31:46]
  • 提交

answer

// #pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>

#include "permutation.h"

std::mt19937 rnd;
int n;

#define TL(val) ;  // assert(clock() * 1.0 / CLOCKS_PER_SEC < val);

int cum(const std::vector<int>& a, const std::vector<int>& p) {
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += abs(a[p[i] - 1] - a[p[i + 1] - 1]);
        TL(0.5);
    }
    return sum;
}

void shuffle(auto& vec) {
    for (int i = 0; i < vec.size(); i++) {
        std::swap(vec[i], vec[rnd() % (i + 1)]);
    }
}

void solve(int n) {
    // while (true) {
    //     assert(clock() * 1.0 / CLOCKS_PER_SEC < 0.6);
    // }

    // return;

    assert(n <= 7);
    TL(0.5);

    ::n = n;
    std::vector<std::vector<int>> all;
    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    shuffle(p);

    {
        int sum0 = query(p);
        std::vector<int> q(n);
        std::iota(q.begin(), q.end(), 1);
        do {
            TL(0.5);
            if (cum(q, p) == sum0) {
                all.push_back(q);
            }
        } while (std::next_permutation(q.begin(), q.end()));
    }

    bool start = true;
    int cnt = 0;
    while (all.size() > 1) {
        cnt++;
        assert(cnt <= 7);
        TL(0.5);

        std::pair<double, std::vector<int>> min(1e9, p);
        for (int iter = 0; iter < 100; iter++) {
            TL(0.5);
            // std::shuffle(p.begin(), p.end(), rnd);
            shuffle(p);
            if (iter < 5) {
                // p = all[iter % all.size()];
                for (int i = 0; i < n; i++) {
                    p[all[iter % all.size()][i] - 1] = i + 1;
                }
            }
            std::vector<int> cum(n * n);

            for (int i = 0; i < all.size(); i++) {
                cum[::cum(all[i], p)]++;
                TL(0.5);
            }

            double cost = 0;
            int cnt = 0;
            for (int i = 0; i < n * n; i++) {
                TL(0.5);
                if (cum[i] > 0) {
                    cost += cum[i] * log2(cum[i]);
                    cnt++;
                }
            }
            min = std::min(min, {cost, p});
            TL(0.5);
        }

        p = min.second;
        TL(0.5);
        int sum0 = query(p);
        TL(0.5);

        bool suc = false;
        for (int i = 0; i < all.size(); i++) {
            TL(0.5);

            if (::cum(all[i], p) != sum0) {
                suc = true;
                all[i] = {};
                TL(0.5);
            }
        }
        if (!suc) {
            break;
        }
        TL(0.5);
        all.erase(std::remove(all.begin(), all.end(), std::vector<int>()), all.end());
    }
    TL(0.5);
    assert(all.size() >= 1);

    answer(all.front());
}

詳細信息

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:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<std::vector<int>, std::allocator<std::vector<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 = std::vector<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
      |              ^~~~~~~~~~~~