#include #include #include #include using namespace std; struct Struct{ int h,w,count; bool operator<(const Struct &other)const{ if(h==other.h) return w=H)return false; if(now.w<0 || now.w>=W)return false; if(field[now.h][now.w]!=color)return false; if(now.h==start.h && now.w==start.w && now.count>3){ return signal=true; } if(dp[now.h][now.w]!=-1){ if((now.count-dp[now.h][now.w])>3){ return signal=true; } return false; } dp[now.h][now.w]=now.count; bool response=false; for(int i=0 ; i<4 ; i++ ){ Struct next; next.h=now.h+direction[i]; next.w=now.w+direction[i+1]; next.count=now.count+1; response|=recursion(next,color); } return response; } int main(){ cin >> W >> H; for(int i=0 ; i> field[i][j]; dp[i][j]=-1; } } for(int i=0 ; i