QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125339#91. Secret PermutationQwerty1232#0 0ms0kbC++202.1kb2023-07-16 16:00:122024-07-04 00:43:36

Judging History

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

  • [2024-07-04 00:43:36]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [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:00:12]
  • 提交

answer

#include <bits/stdc++.h>

#include "permutation.h"

std::mt19937 rnd;
int n;

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]);
    }
    return sum;
}

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

    bool start = true;
    while (all.size() > 1) {
        std::pair<double, std::vector<int>> min(1e9, p);
        for (int iter = 0; iter < 10; iter++) {
            std::shuffle(p.begin(), p.end(), rnd);
            if (iter < 3) {
                // 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)]++;
            }

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

        int sum0 = query(p);

        bool suc = false;
        for (int i = 0; i < all.size(); i++) {
            if (::cum(all[i], p) != sum0) {
                suc = true;
                all[i] = {};
            }
        }
        if (!suc) {
            break;
        }
        all.erase(std::remove(all.begin(), all.end(), std::vector<int>()), all.end());
    }
    assert(all.size() >= 1);
    answer(all.front());
};

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

7
5 7 1 3 2 4 6

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%