//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int l,r,n,m,mk[30][30],st,c;
char s[30][30],land;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
void dfs(int x,int y){
c++;
mk[x][y]=1;
if(x==l && y==r)
st=1;
int i,j,p,q;
f(i,0,8){
p=x+dx[i];q=(y+dy[i]+m)%m;
if(p>=0 && p<n && !mk[p][q] && s[p][q]==land)
dfs(p,q);
}
}
int main(){
int k,i,x=0,y=0,j,t,z,x1=0,y1=0;
ll ans=0;
while(sii(n,m)!=EOF){
clr(mk,0);
f(i,0,n)
scanf("%s",s[i]);
sii(l,r);
land=s[l][r];
z=0;
f(i,0,n){
f(j,0,m){
st=0;c=0;
if(!mk[i][j] && s[i][j]==land){
dfs(i,j);
if(!st)
z=max(z,c);
}
}
}
pi(z);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int l,r,n,m,mk[30][30],st,c;
char s[30][30],land;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
void dfs(int x,int y){
c++;
mk[x][y]=1;
if(x==l && y==r)
st=1;
int i,j,p,q;
f(i,0,8){
p=x+dx[i];q=(y+dy[i]+m)%m;
if(p>=0 && p<n && !mk[p][q] && s[p][q]==land)
dfs(p,q);
}
}
int main(){
int k,i,x=0,y=0,j,t,z,x1=0,y1=0;
ll ans=0;
while(sii(n,m)!=EOF){
clr(mk,0);
f(i,0,n)
scanf("%s",s[i]);
sii(l,r);
land=s[l][r];
z=0;
f(i,0,n){
f(j,0,m){
st=0;c=0;
if(!mk[i][j] && s[i][j]==land){
dfs(i,j);
if(!st)
z=max(z,c);
}
}
}
pi(z);
}
return 0;
}
No comments:
Post a Comment