Submission #440441

#TimeUsernameProblemLanguageResultExecution timeMemory
440441colossal_pepeEmacs (COCI20_emacs)C++17
50 / 50
2 ms460 KiB
#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 timeMemoryGrader output
Fetching results...