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------------------------------
//******************************************************************
#define IOS ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0)
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
#define endl "\n"
//******************************************************************
//----------------------------FUNCTION------------------------------
//******************************************************************
ll gcd(ll a,ll b){
if(a>b) swap(a,b);
if(a==0) return a+b;
return gcd(b%a,a);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
bool is_prime(ll n){
ll k=sqrt(n);
if(n==2) return true;
if(n<2||n%2==0||k*k==n) return false;
for(int i=3;i<=k;i+=2){
if(n%i==0){
return false;
}
}
return true;
}
//*****************************************************************
//--------------------------MAIN-CODE------------------------------
const int mxn=2e5+5;
int t=1,n,say=1e7;
map<vector<int>,bool>mp;
vector<int>ans;
void f1(vector<int>&vt){
for(int i=0;i<vt.size()/2;i++){
swap(vt[i],vt[i+(vt.size()/2)]);
}
}
vector<int>f2(vector<int>&vt){
vector<int>ans;
for(int i=0;i<vt.size();i+=2){
ans.pb(vt[i]);
}
for(int i=1;i<vt.size();i+=2){
ans.pb(vt[i]);
}
return ans;
}
int calc(vector<int>&vt){
int ans=0;
for(int i=0;i<vt.size();i++){
for(int j=i+1;j<vt.size();j++){
if(vt[i]>vt[j]){
ans++;
}
}
}
return ans;
}
void funk(vector<int>vt,vector<int>res,int x){
if(x==1){
f1(vt);
res.pb(1);
}
else if(x==2){
vt=f2(vt);
res.pb(2);
}
if(mp[vt]) return;
mp[vt]=1;
int xx=calc(vt);
if(xx<say){
say=xx;
ans=res;
}
funk(vt,res,1);
funk(vt,res,2);
}
void solve(){
vector<int>vt;
cin>>n;
for(int i=1;i<=(1<<n);i++){
int x;
cin>>x;
vt.pb(x);
}
funk(vt,{},-1);
cout<<say<<endl;
for(int v:ans){
cout<<v;
}
cout<<endl;
}
int main(){
IOS;
//cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
cheerleaders.cpp: In function 'void f1(std::vector<int>&)':
cheerleaders.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0;i<vt.size()/2;i++){
| ~^~~~~~~~~~~~
cheerleaders.cpp: In function 'std::vector<int> f2(std::vector<int>&)':
cheerleaders.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=0;i<vt.size();i+=2){
| ~^~~~~~~~~~
cheerleaders.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=1;i<vt.size();i+=2){
| ~^~~~~~~~~~
cheerleaders.cpp: In function 'int calc(std::vector<int>&)':
cheerleaders.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<vt.size();i++){
| ~^~~~~~~~~~
cheerleaders.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=i+1;j<vt.size();j++){
| ~^~~~~~~~~~
# | 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... |