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 <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
int N, A[1<<17];
int inv() {
int cnt = 0;
FOR(i,0,(1<<N)-1){
FOR(j,0,i-1){
if (A[j] > A[i]) ++cnt;
}
}
return cnt;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N;
FOR(i,0,(1<<N)-1){
cin >> A[i];
}
vector<int> ops;
while (true) {
bool done = 1;
int pos0 = -1;
FOR(i,0,(1<<N)-1){
done &= A[i] == i;
if (A[i] == 0) pos0 = i;
}
if (done) break;
int op;
if (pos0 < (1<<(N-1))) op = 2;
else op = 1;
ops.push_back(op);
if (op == 1) {
FOR(i,0,(1<<(N-1))-1){
swap(A[i],A[i+(1<<(N-1))]);
}
} else {
vector<int> v[2];
FOR(i,0,(1<<N)-1) v[i&1].push_back(A[i]);
FOR(i,0,(1<<(N-1))-1) A[i] = v[0][i];
FOR(i,0,(1<<(N-1))-1) A[i+(1<<(N-1))] = v[1][i];
}
}
cout << 0 << '\n';
for (int& x : ops) {
cout << x;
}
}
# | 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... |