# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1273924 | SmuggingSpun | Emacs (COCI20_emacs) | C++20 | 2 ms | 580 KiB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
const int lim = 105;
char a[lim][lim];
int n, m, ans = 0;
void dfs(int x, int y){
if(x < 1 || x > n || y < 1 || y > m || a[x][y] != '*'){
return;
}
a[x][y] = '.';
dfs(x - 1, y);
dfs(x + 1, y);
dfs(x, y - 1);
dfs(x, y + 1);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i][j] == '*'){
ans++;
dfs(i, j);
}
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |