#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=1e6,M=2e3,mod=1e9+7;
int dp[2][51][51][10001];
string s[N];
int cnt=1;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
int n,m,vis[105][105];
bool inside(int x,int y){
return (x<n)&&(x>=0)&&(y<m)&&(y>=0)&&(s[x][y]=='*');
}
void floodfill(int x,int y){
vis[x][y]=1;
for(int i=0;i<4;i++){
int newx=x+dx[i];
int newy=y+dy[i];
if(inside(newx,newy)&&vis[newx][newy]==0)
floodfill(newx,newy);
}
}
main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
if(!vis[i][j]&&s[i][j]=='*')
floodfill(i,j),cnt++;
}
cout<<cnt-1<<endl;
return 0;
}
Compilation message
emacs.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
31700 KB |
Output is correct |
2 |
Correct |
16 ms |
31768 KB |
Output is correct |
3 |
Correct |
17 ms |
31700 KB |
Output is correct |
4 |
Correct |
15 ms |
31572 KB |
Output is correct |
5 |
Correct |
16 ms |
31632 KB |
Output is correct |
6 |
Correct |
17 ms |
31572 KB |
Output is correct |
7 |
Correct |
20 ms |
31700 KB |
Output is correct |
8 |
Correct |
17 ms |
31768 KB |
Output is correct |
9 |
Correct |
16 ms |
31828 KB |
Output is correct |
10 |
Correct |
22 ms |
31700 KB |
Output is correct |