#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define pb emplace_back typedef long long ll; typedef pair pint; unsigned long xor128(){ static unsigned long x=123456789,y=362436069,z=521288629,w=88675123; unsigned long t=(x^(x<<11)); x=y;y=z;z=w; return (w=(w^(w>>19))^(t^(t>>8))); } double timeLimit=0.91; const int64_t CYCLES_PER_SEC=2800000000; struct Timer { int64_t start; Timer() { reset(); } void reset() { start = getCycle(); } void plus(double a) { start -= (a * CYCLES_PER_SEC); } inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; } inline int64_t getCycle() { uint32_t low, high; __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high)); return ((int64_t)low) | ((int64_t)high << 32); } }; int n,k; pint L[501]; string s[61]; bool g[61][61]; //vector > cand(7201); vector > ans; int lx,rx,ly,ry; pair calc(int length){ pair ret; pint best={-1000100010,0}; pint score; int slide=1; rep(i,n)rep(j,n-length+1)if(g[i][j]|g[i][j+length-1]){ score={0,0}; slide=1; //while(j-slide>=0&&g[i][j-slide]!=g[i][j]&&slide<3) ++score.second,++slide; while(j-slide>=0&&g[i][j-slide]^g[i][j]) ++score.second,++slide; slide=length; //while(j+slide0&&g[i][j+k-1]==g[i][j+k]) ++score.second; /* slide=1; while(i-slide>=0&&g[i][j+k]!=g[i-slide][j+k]&&slide<3) ++score.second,++slide; slide=1; while(i+slide=0&&g[j-slide][i]!=g[j][i]&&slide<3) ++score.second,++slide; while(j-slide>=0&&g[j-slide][i]^g[j][i]) ++score.second,++slide; slide=length; //while(j+slide0&&g[j+k-1][i]==g[j+k][i]) ++score.second; /* slide=1; while(i-slide>=0&&g[j+k][i]!=g[j+k][i-slide]&&slide<3) ++score.second,++slide; slide=1; while(i+slide calc2(pair &tget){ pair ret; pint best={-1000100010,0}; //int lx,rx,ly,ry; ly=tget.first.first,lx=tget.first.second,ry=tget.second.first,rx=tget.second.second; FOR(i,ly,ry+1)FOR(j,lx,rx+1) g[i-1][j-1]^=1; int length=(ry-ly)==0?rx-lx+1:ry-ly+1; int slide=1; rep(i,n)rep(j,n-length+1)if(g[i][j]|g[i][j+length-1]){ pint score={0,0}; slide=1; while(j-slide>=0&&g[i][j-slide]^g[i][j]) ++score.second,++slide; slide=length; while(j+slide0&&g[i][j+k-1]==g[i][j+k]) ++score.second; } if(best=0&&g[j-slide][i]^g[j][i]) ++score.second,++slide; slide=length; while(j+slide0&&g[j+k-1][i]==g[j+k][i]) ++score.second; } if(best>n>>k; int Li; rep(i,k){ cin>>Li; L[i]={Li,i}; } //sort(L,L+k,greater()); rep(i,n) cin>>s[i]; ans.resize(k); rep(i,n)rep(j,n){ g[i][j]|=s[i][j]-'0'; } rep(i,k){ ans[L[i].second]=calc(L[i].first); } int id; double t; while(1){ t=timer.get(); if(t>timeLimit) break; id=xor128()%k; ans[id]=calc2(ans[id]); } rep(i,k){ cout<