ELDVN
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
bool canMove(int x, int y) {
return (0 <= x and x < n) and (0 <= y and y < m) and (a[x][y] == 'X');
}
int getMaxShape() {
int res = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = 0; j < m; j++) {
if (a[i][j] == 'X') {
dfs(i, j, cnt);
}
}
res = max(res, cnt);
}
return res;
}
void dfs(int x, int y, int& cnt) {
cnt++;
a[x][y] = '.';
for (int dx = 1; dx <= 1; dx++) {
for (int dy = 1; dy <= 1; dy++) {
if (dx * dx + dy * dy == 1) {
if (canMove(dx + x, dy + y)) {
dfs(dx + x, dy + y, cnt);
}
}
}
}
}

ELDVN
October 23, 2017 Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Open Chat in New Window
Open Chat in New Window
 ELDVN October 23, 2017