Untitled

 avatar
unknown
c_cpp
a year ago
1.6 kB
3
Indexable
// Author: masked_huh
// Created: 2021-04-01 13:33:15
 
/*Success isn't permanent, failure isn't fatal,
it's the courage to continue that counts.*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define vi vector<int> 
#define vc vector<char>
 
const ll mod = 1e9 + 7;
 
int X[4]={1,-1,0,0};
int Y[4]={0,0,1,-1};
 
bool check(vector<string>&str,int x,int y)
{
	int n=str.size();
	int m=str[0].size();
 
	if((x<0)||(x>=n))
		return false;
	if((y<0)||(y>=m))
		return false;
	if(str[x][y]=='#')
		return false;
	return true;
}
 
void dfs(vector<string>&str,int x,int y)
{
	int n=str.size();
	int m=str[0].size();
 
	str[x][y]='#';
 
	f(rep,0,4)
	{
		int tx=x+X[rep];
		int ty=y+Y[rep];
 
		if(check(str,tx,ty))
			dfs(str,tx,ty);
	}
	return;
}
 
void solve()
{
	int n,m;
	sfi(n)
	sfi(m)
 
	vector<string>str(n);
 
	f(i,0,n)
		cin>>str[i];
 
	int cnt=0;
 
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(str[i][j]=='.')
			{
				cnt++;
				dfs(str,i,j);
			}
		}
	}
 
	pfin(cnt)
 
    return;
}
 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
 
	int t=1;
	//sfi(t)
 
	while(t--)
		solve();
 
    return 0;
}
Leave a Comment