#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<<"("< data; Field(int h,int w){ height = h; width = w; data.resize(h*w); } int& operator()(int y,int x){ return data[y*width+x]; } bool operator<(const Field& f) const{ return data < f.data; } bool operator==(const Field& f) const{ return height==f.height && width == f.width && data == f.data; } void flipx(){ int x,y; for (y=0;y dp; void flipx(vector>& field){ int x,y; for (y=0;y>& field){ int x,y; for (y=0;y> height >> width; Field first(height,width); // cww Field final(height,width); // zero for (y=0;y> first(y,x); } } // all zero queue > q; //q.push(make_pair(1,final)); q.push(make_pair(1,first)); dp[final] = 1; //q.push(make_pair(10001,first)); //dp[first] = 10001; auto tim = TIME; while (!q.empty()){ if (MILLISEC(TIME-tim)>7000) break; auto p = q.front(); q.pop(); //if (dp.size()>100000){ // cout << dp.size() << endl;return 0; //} if (p.second == final){ cout << (p.first-1) << endl; return 0; } // if (p.first<10000 && p.second == first){ // cout << (p.first-1) << endl; // return 0; // } // if (p.first>=10000 && p.second == final){ // cout << (p.first-10001) << endl; // return 0; // } for (y=0;y