static int f_row(int y,int p[6],int d[36][6]){ int z=0; int v[6]{}; int n[6]{}; rep(x,6){ int i=p[y*6+x]; rep(k,6){ int c=d[i][k]; v[c]|=1<=i; if(1){ swap(p[i],p[j]); int sir=0; int sic=0; int sjr=0; int sjc=0; int e=0; if(i/6!=j/6){ sir=f_row(i/6,p,d); sjr=f_row(j/6,p,d); e+=sir+sjr-s_row[i/6]-s_row[j/6]; } if(i%6!=j%6){ sic=f_col(i%6,p,d); sjc=f_col(j%6,p,d); e+=sic+sjc-s_col[i%6]-s_col[j%6]; } if(r.get(0.,1.)best_s){ best_s=s; rep(i,36)best_p[i]=p[i]; } }else{ swap(p[i],p[j]); } } } { int o[36]; rep(i,36){ o[best_p[i]]=i; } rep(i,36){ wt(o[i]/6+1,o[i]%6+1); } } }