#include #include #include #include #include #define M 405 using namespace std; fstream fin("ferma.in",ios::in),fout("ferma.out",ios::out); int di[]={-1,0,1,0},dj[]={0,1,0,-1}; deque > d; int cost[M*M],who[M][M]; bitset bit[M]; string s[M]; int n,m,t,ir,jr; char color; void citire(){ fin>>t>>n>>m; for(int i=0;i>s[i]; } bool ok(int i,int j){ if(-1=maxim) { color=s[c][d]; ir=a; jr=b; maxim=cost[who[c][d]]+1; } } else { if(cost[who[c][d]]+cost[who[e][f]]+1>=maxim) { color=s[c][d]; ir=a; jr=b; maxim=cost[who[c][d]]+cost[who[e][f]]+1; } } } } } } int search() { int maxim=-9999,r; for(int i=0;i #include #include #include #define M 405 using namespace std; fstream fin("ferma.in",ios::in),fout("ferma.out",ios::out); int di[]={-1,0,1,0},dj[]={0,1,0,-1},n,m,t,who[M][M],cost[M*M],aux[M*M]; queue > v; char color,s[M][M]; void citire(){ fin>>t>>n>>m; for(int i=1;i<=n;i++) fin>>s[i]+1; } int bfs(int i,int j,int ind) { int total=1,k; who[i][j]=ind; v.push(make_pair(i,j)); while(!v.empty()) { i=v.front().first; j=v.front().second; for(k=0;k<4;k++) { if(s[i+di[k]][j+dj[k]]==s[i][j]&&0