#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <fstream>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int dy[4]={0, 0, -1, 1};
int dx[4]={1, -1, 0, 0};
int n, m;
vector<vector<bool> > visited;
vector<string> graph;
void dfs(int x, int y){
visited[x][y]=1;
for (int i=0; i<4; ++i){
int nx=x+dx[i], ny=y+dy[i];
if (nx<0||ny<0||nx>=n||ny>=m||visited[nx][ny]||graph[nx][ny]!='*')continue;
dfs(nx, ny);
}
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ans=0;
cin>>n>>m;
graph.resize(n);
visited.resize(n, vector<bool>(m, 0));
for (int i=0; i<n; ++i)cin>>graph[i];
for (int i=0; i<n; ++i)for (int j=0; j<m; ++j)if (!visited[i][j]&&graph[i][j]=='*')dfs(i, j), ++ans;
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |