#include using namespace std; typedef unsigned int uint; typedef long long int ll; typedef unsigned long long int ull; #define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<>=1,k++)s=(s<<1)|(u&1);for(;0>=1)cout<<(s&1);}} #define TIME chrono::system_clock::now() #define MILLISEC(t) (chrono::duration_cast(t).count()) template ostream& operator <<(ostream &o,const pair p){o<<"("<>,int> dp; int main(){ int i,j,k; int x,y,a,b; cin >> height >> width; vector> first; // valarray vector> final; for (y=0;y> first[y][x]; } } // all zero queue>> > q; q.push(make_pair(0,final)); while (!q.empty()){ pair>> p = q.front(); q.pop(); if (p.second == first){ cout << p.first << endl; return 0; } for (y=1;y> tmp = p.second; for (i=-1;i<=1;i++){ for (j=-1;j<=1;j++){ tmp[y+j][x+i]^=1; } } int &val = dp[tmp]; if (!val){ val = 1; q.push(make_pair(p.first+1,tmp)); } } } } cout << -1 << endl; return 0; }