-
Notifications
You must be signed in to change notification settings - Fork 1
/
UVA_11094.cpp
65 lines (58 loc) · 1.13 KB
/
UVA_11094.cpp
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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define endl "\n"
#define newline cout << "\n"
#define puts(_content_) cout << _content_ << "\n"
using namespace std;
int M, N;
char mp[25][25];
char land;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int mod (int y)
{
if(y < 0) return N-1;
return y % N;
}
int dfs (int x, int y) {
int ret = 1;
mp[x][y] = ' ';
REP(i, 0, 4) {
int nx = x + dx[i];
int ny = mod(y + dy[i]);
if(nx >= 0 && nx < M && mp[nx][ny] == land) {
ret += dfs(nx, ny);
}
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
#ifndef Home
freopen ("input.txt", "r", stdin);
#endif
while(cin >> M >> N) {
REP(i, 0, M) {
REP(j, 0, N) {
cin >> mp[i][j];
}
}
int x0, y0;
cin >> x0 >> y0;
land = mp[x0][y0];
dfs(x0, y0);
int answer = 0;
REP(i, 0, M) {
REP(j, 0, N) {
if(mp[i][j] == land) {
answer = max(answer, dfs(i, j));
}
}
}
puts(answer);
}
return 0;
}