-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP11094.cpp
60 lines (57 loc) · 1.24 KB
/
P11094.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
// Coordinates (x,y) ~ (M,N)
int handle(int x, int y, bool map[][22], int M, int N) {
if(!map[x][y])
return 0;
int ret = 1;
map[x][y] = false;
if(x > 0)
ret += handle(x-1, y, map, M, N);
if(x < M-1)
ret += handle(x+1, y, map, M, N);
ret += handle(x, (y+1)%N, map, M, N);
ret += handle(x, (y+N-1)%N, map, M, N);
return ret;
}
int main() {
int M, N;
bool map[22][22]; // true => land.
string line;
while(true) {
getline(cin, line);
stringstream ss1; ss1 << line; if(!(ss1 >> M >> N)) return 0;
char firstChar;
FORX(M) {
getline(cin, line);
if((int)line.size() != N)
die();
if(x == 0)
firstChar = line[0];
FORY(N) {
map[x][y] = line[y] == firstChar;
}
}
getline(cin, line);
int kx, ky;
stringstream ss2; ss2 << line; ss2 >> kx >> ky;
if(!map[kx][ky]) {
// FLIP ALL!
FORY(N) {
FORX(M) {
map[x][y] = !map[x][y];
}
}
}
handle(kx, ky, map, M, N);
int max = 0;
FORY(N) {
FORX(M) {
int continentSize = handle(x,y, map, M, N);
//cerr << "Continent at " << x << "," << y << ": " << continentSize << endl;
max = MAX(max,continentSize);
}
}
cout << max << endl;
getline(cin, line);
}
return 0;
}