This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define endl '\n'
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 2 * 1e5;
char arr[1001][1001];
int numArr[1001][1001];
int n,m;
void DFS(int i, int j, int num, char parent){
if(i < 0 || i >= n) return;
if(j < 0 || j >= m) return;
if(arr[i][j] != parent) return;
if(numArr[i][j] != 0) return;
numArr[i][j] = num;
DFS(i-1, j, num, parent);
DFS(i+1, j, num, parent);
DFS(i, j+1, num, parent);
DFS(i, j-1, num, parent);
}
void solve(){
cin>>n>>m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin>>arr[i][j];
numArr[i][j] = 0;
}
}
int cur = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(numArr[i][j] == 0 && arr[i][j] != '*'){
DFS(i,j,cur,arr[i][j]);
cur++;
}
}
}
cout<<cur-1;
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin >> t;
while(t--){
//cout<<"Case #"<<t<<" > "<<endl;
solve();
cout<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |