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=f_row(i/6,p,d); int sic=f_col(i%6,p,d); int sjr=0; int sjc=0; int e=sir+sic-s_row[i/6]-s_col[i%6]; if(i/6!=j/6){ sjr=f_row(j/6,p,d); e+=sjr-s_row[j/6]; } if(i%6!=j%6){ sjc=f_col(j%6,p,d); e+=sjc-s_col[j%6]; } b+=e>=0?1:exp(e*1.1); if(b>=1){ b-=1; s_row[j/6]=sjr; s_row[i/6]=sir; s_col[j%6]=sjc; s_col[i%6]=sic; s+=e; if(s>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); } } }