이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i = a; i < b; i++)
const int inf = 2e9;
int n;
int ans = inf;
vector <int> res;
map <vector <int>, bool> on;
void go(vector <int> v, vector <int> &curr){
int inver = 0;
f(i,0,n) f(j,i+1,n) if(v[i] > v[j]) inver++;
on[v] = 1;
if(inver < ans){
ans = inver;
res = curr;
}
f(i,1,3){
curr.push_back(i);
vector <int> aux;
if(i == 1){
f(j,n/2,n) aux.push_back(v[j]);
f(j,0,n/2) aux.push_back(v[j]);
}
else{
f(j,0,n) if(j%2 == 0) aux.push_back(v[j]);
f(j,0,n) if(j%2 != 0) aux.push_back(v[j]);
}
if(!on[aux]) go(aux, curr);
curr.pop_back();
}
}
int main(){
vector <int> v, curr;
cin >> n;
n = (1<<n);
f(i,0,n){
int x;
cin >> x;
v.push_back(x);
}
go(v, curr);
cout << ans << "\n";
for(int x: res) cout << x;
if(res.size()) cout << "\n";
return 0;
}
# | 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... |