#include #include #include #include #include using namespace std; typedef long long lint; typedef vectorvi; typedef pairpii; #define rep(i,n)for(int i=0;i<(int)(n);++i) const int DEBUG=0; const int K=500; int l[K]; const int N=60; string a[N]; int b[N][N]; int calc_score(const vector&ans){ int c[N][N]; rep(i,N)rep(j,N)c[i][j]=b[i][j]; rep(i,ans.size()){ if(ans[i].second<0){ assert(ans[i].first+l[i]-1<=N); rep(j,l[i]) c[ans[i].first+j-1][-ans[i].second-1]^=1; } else{ assert(ans[i].second+l[i]-1<=N); rep(j,l[i]) c[ans[i].first-1][ans[i].second+j-1]^=1; } } int t=0; rep(i,N)rep(j,N)t+=1-c[i][j]; return t; } void output(const vector&ans){ int orig=calc_score(vector()); rep(i,ans.size()){ if(ans[i].second<0) cout< nxt(cur); int idx=len[u][mt()%len[u].size()]; pair tt(-1,pii(-1,-1)); rep(j,N){ nxt[idx].first=mt()%(N-l[idx]+1)+1; nxt[idx].second=-(j+1); tt=max(tt,make_pair(calc_score(nxt),nxt[idx])); } rep(i,N){ nxt[idx].first=i+1; nxt[idx].second=mt()%(N-l[idx]+1)+1; tt=max(tt,make_pair(calc_score(nxt),nxt[idx])); } nxt[idx]=tt.second; int nxtsc=calc_score(nxt); if(nxtsc>=sc){ cur=nxt; sc=nxtsc; } if(sc>ma){ if(DEBUG){ if(fire){ cerr<<"updmax "<"<