# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
753694 | Stickfish | Cheerleaders (info1cup20_cheerleaders) | C++17 | 2055 ms | 3616 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
ll get_inversion(vector<int>& p) {
int n = p.size();
ll ans = 0;
for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) {
ans += p[i] > p[j];
}
return ans;
}
vector<int> combine_permutations(vector<int> a, vector<int> b) {
int n = a.size();
vector<int> ans(n);
for (int i = 0; i < n; ++i) {
ans[i] = b[a[i]];
}
return ans;
}
vector<int> reverse_permutation(vector<int> a) {
int n = a.size();
vector<int> ans(n);
for (int i = 0; i < n; ++i)
ans[a[i]] = i;
return ans;
}
pair<ll, string> get_ans(vector<int> p) {
int n = p.size();
vector<int> aaa = p;
ll ans = get_inversion(aaa);
int ansx = 0;
//for (int bt = n / 2; bt > 0; bt /= 2) {
//int nx = ansx + bt;
for (int nx = 0; nx < n; ++nx) {
vector<int> op(n);
for (int i = 0; i < n; ++i)
op[i] = i ^ nx;
vector<int> np = combine_permutations(op, p);
ll nans = get_inversion(np);
if (nans < ans) {
ans = nans;
ansx = nx;
}
}
//cout << ans << ' ' << ansx << endl;
return {ans, "12111"};
}
signed main() {
int N;
cin >> N;
int m = (1 << N);
vector<int> p(m);
for (int i = 0; i < m; ++i)
cin >> p[i];
vector<int> op1(m);
vector<int> op2(m);
for (int i = 0; i < m; ++i) {
op1[i] = i ^ (m / 2);
op2[i] = (i >> 1) + ((i & 1) << (N - 1));
}
ll ans = 1ll * m * m;;
string ansa;
for (int t = 0; t < N; ++t) {
auto [nans, nansa] = get_ans(p);
if (nans < ans) {
ans = nans;
ansa = nansa;
}
p = combine_permutations(op2, p);
}
cout << ans << '\n';
cout << ansa << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |