#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.85; 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,W0; int L[501]; string s[61]; vector > g(101,vector(101,0)),tg(101,vector(101,0)); vector > ans,tmp; pair calc(int length){ int best=-1000100010; int lx,rx,ly,ry; vector > cand; rep(i,n)rep(j,n-length+1){ int score=0; rep(k,length){ if(g[i][j+k]==1) ++score; else --score; } if(best ret=cand[xor128()%sz]; ly=ret.first.first,ry=ret.first.second,lx=ret.second.first,rx=ret.second.second; FOR(i,ly,ry+1)FOR(j,lx,rx+1) g[i-1][j-1]^=1; return make_pair(pint(ly,lx),pint(ry,rx)); } int get_score(){ int ret=0; rep(i,n)rep(j,n)if(g[i][j]==0) ++ret; return ret; } int main(){ Timer timer; timer.reset(); cin>>n>>k; rep(i,k) cin>>L[i]; rep(i,n) cin>>s[i];; tmp.resize(k);ans.resize(k); rep(i,n)rep(j,n){ g[i][j]=s[i][j]-'0'; } tg=g; int bestscore=-1000100010; while(timer.get() ret=calc(L[i]); tmp[i]=ret; //cout<