답안 #440441

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440441 2021-07-02T09:19:26 Z colossal_pepe Emacs (COCI20_emacs) C++17
50 / 50
2 ms 460 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 460 KB Output is correct