# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440441 | colossal_pepe | Emacs (COCI20_emacs) | C++17 | 2 ms | 460 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstring>
using namespace std;
int n, m;
char grid[105][105];
bool visited[105][105];
void dfs(int i, int j) {
if (visited[i][j]) return;
visited[i][j] = 1;
if (grid[i - 1][j] == '*') dfs(i - 1, j);
if (grid[i + 1][j] == '*') dfs(i + 1, j);
if (grid[i][j - 1] == '*') dfs(i, j - 1);
if (grid[i][j + 1] == '*') dfs(i, j + 1);
}
int main() {
memset(grid, '.', sizeof(grid));
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> grid[i][j];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (grid[i][j] == '*' and not visited[i][j]) {
dfs(i, j);
ans++;
}
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |