답안 #863397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863397 2023-10-20T06:58:17 Z vjudge1 Emacs (COCI20_emacs) C++17
50 / 50
1 ms 604 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long

using namespace std;

typedef tuple<int, int, int> iii;
typedef long long ll;
const int mod =998244353;

int n, m, ans;
char c[105][105];
bool vis[105][105];
void dfs(int i, int j){
	if(i<1 || i>n || j<1 || j>m || c[i][j]=='.' || vis[i][j])return;
	vis[i][j]=true;
	dfs(i-1, j);
	dfs(i+1, j);
	dfs(i, j+1);
	dfs(i, j-1);
}
int32_t main(){
	fast;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(vis[i][j])continue;
			if(c[i][j]=='.')continue;
			ans++;
			dfs(i, j);
		}
	}
	cout<<ans<<endl;
}	

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct