-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11094.cpp
More file actions
executable file
·99 lines (93 loc) · 2.51 KB
/
11094.cpp
File metadata and controls
executable file
·99 lines (93 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <bits/stdc++.h>
using namespace std;
#define tani_nachi_ke ios_base::sync_with_stdio(false); cin.tie(NULL);
bool arr[21][21];
int n,m;
int ct;
void fun(int i,int j)
{
if(i<0||i>=n||j<0||j>=m)return ;
if(!arr[i][j%m])return;
arr[i][j%m]=false;
ct++;
fun(i-1,j);
fun(i+1,j);
fun(i,((j-1+m)%m));
fun(i,((j+1+m)%m));
}
int main()
{
tani_nachi_ke
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(!cin.eof())
{
cin>>n;
cin>>m;
memset(arr,false,sizeof(arr));
string s;
char c;
for(int i=0; i<n; i++)
{
cin>>s;
transform(s.begin(),s.end(),s.begin(),::tolower);
//cout<<s<<endl;
for(int j=0; j<s.size(); j++)
{
if(i==0&&j==0)
{
arr[i][j]=true;
c=s[j];
}
else if(s[j]==c)arr[i][j]=true;
else arr[i][j]=false;
}
// cout<<s<<endl;
}
int startx,starty;
cin>>startx;
cin>>starty;
if(!arr[startx][starty])
{
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)arr[i][j]=(arr[i][j]^1);
}
fun(startx,starty);
int mx=0;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
if(arr[i][j])
{
queue<pair<int,int>> q;
q.push({i,j});
while(!q.empty())
{
pair<int,int> cord=q.front;
q.pop();
int curx=cord.first;
int cury=cord.second;
for(int l=-1; l<=1; l++)
for(int r=-1; r<=1; r++)
{
if(abs(l+r)==1&&curx+l>=0&&curx+l<n)
{
if(arr[l+curx][(cury+m+r)%m])
{
arr[l+curx][(cury+m+r)%m]=true;
q.push({l+curx,(cury+r+m)%m});
}
}
}
}
ct=0;
fun(i,j);
mx=max(ct,mx);
}
}
}
cout<<mx<<endl;
getline(cin,s);
}
}