QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#125339 | #91. Secret Permutation | Qwerty1232# | 0 | 0ms | 0kb | C++20 | 2.1kb | 2023-07-16 16:00:12 | 2024-07-04 00:43:36 |
Judging History
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());
};
詳細信息
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%