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;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[1000009],pasii,pasjj,g[1000009],n,fen[1000009],ff[1000009];
long long pas,jm;
void upd(int q){
while(q<=a+2){
fen[q]++;
q=q+(q&(-q));
}
}
int read(int q){
int sm=0;
while(q>=1){
sm+=fen[q];
q=q-(q&(-q));
}
return sm;
}
int main(){
//freopen("magalitiinput.txt","r",stdin);
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
a=1;
for(i=1; i<=n; i++) a*=2;
for(i=0; i<a; i++){
cin>>g[i];
f[i]=i;
}
if(n==0){
cout<<0<<endl;
return 0;
}
pas=a;pas=pas*pas;
pasii=-1;pasjj=-1;
if(n>7){
for(ii=0; ii<n; ii++){
c=-1;
if(ii!=0){
for(i=0; i<a; i++){
if(f[i]%2==0){
f[i]/=2;
}else{
f[i]=f[i]/2+(1<<(n-1));
}
}
}
for(i=0; i<a; i++){
if(c==-1){
c=(f[i]^g[i]);
}else{
d=(f[i]^g[i]);
if(c!=d) break;
}
}
if(i==a){
pasii=ii;pasjj=c;
break;
}
}
//cout<<pasii<<" "<<pasjj<<endl;
cout<<0<<endl;
for(i=0; i<n; i++){
//c=n-1-i-pasii;if(c<0) c=n+c;
c=n-1+i;if(c>=n) c-=n;
c=c-pasii;if(c<0) c=n+c;
//cout<<"kkk"<<c<<endl;
if(((1<<c)&pasjj)==0){
}else{
cout<<1;
}
cout<<2;
}
for(i=0; i<pasii; i++) cout<<2;
return 0;
}
pas=a;pas=pas*pas;
pasii=-1;pasjj=-1;
for(ii=0; ii<n; ii++){
c=-1;
if(ii!=0){
for(i=0; i<a; i++){
if(f[i]%2==0){
f[i]/=2;
}else{
f[i]=f[i]/2+(1<<(n-1));
}
}
}
for(jj=0; jj<(1<<n); jj++){
for(i=0; i<a; i++) ff[i]=(g[(f[i]^jj)]);
for(i=0; i<=a+2; i++) fen[i]=0;
jm=0;
for(i=a-1; i>=0; i--){
jm+=read(ff[i]+1);
upd(ff[i]+1);
}
/*if(jm==0){
cout<<ii<<" lp "<<jj<<endl;
for(i=0; i<a; i++) cout<<ff[i]<<" k ";
cout<<endl;
}*/
if(pas>jm){
pas=jm;pasii=ii;pasjj=jj;
}
}
}
//cout<<pasii<<" "<<pasjj<<endl;
cout<<pas<<endl;
for(i=0; i<n; i++){
c=n-1+i;if(c>=n) c-=n;
c=c-pasii;if(c<0) c=n+c;
if(((1<<c)&pasjj)==0){
}else{
cout<<1;
}
cout<<2;
}
for(i=0; i<pasii; i++) cout<<2;
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... |