//Test case unutma ve reset
//Sinirlari kontrol et
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1e9+7
#define OYY 1e12
#define ordu ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mid (start+end)/2
int vis[105][105];
char dizi[105][105];
int n,m;
void dfs(int i,int j){
vis[i][j]=1;
if(i+1<n && vis[i+1][j]==0){
if(dizi[i+1][j]=='*'){
dfs(i+1,j);
}
}
if(j+1<m && vis[i][j+1]==0){
if(dizi[i][j+1]=='*'){
dfs(i,j+1);
}
}
if(i-1>=0 && vis[i-1][j]==0){
if(dizi[i-1][j]=='*'){
dfs(i-1,j);
}
}
if(j-1>=0 && vis[i][j-1]==0){
if(dizi[i][j-1]=='*'){
dfs(i,j-1);
}
}
return ;
}
int32_t main(){
ordu
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>dizi[i][j];
}
}
int cev=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(dizi[i][j]=='*' && vis[i][j]==0){
cev++;
dfs(i,j);
}
}
}
cout<<cev<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |