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 int long long
#define pb push_back
#define fir first
#define sec second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m,vis[1005][1005],sum,t=0;
char a[1005][1005];
void bfs(char c,int x,int y){
t=0;
queue<pair<int,int>> q;
q.push({x,y});
while(!q.empty()){
x=q.front().fir;
y=q.front().sec;
q.pop();
if(a[x][y]!=c) continue;
if(c=='B') a[x][y]='T';
else a[x][y]='B';
t++;
if(a[x+1][y]==c)
q.push({x+1,y});
if(a[x-1][y]==c)
q.push({x-1,y});
if(a[x][y+1]==c)
q.push({x,y+1});
if(a[x][y-1]==c)
q.push({x,y-1});
}
return;
}
int32_t main(){
int ans=0;
memset(vis,0,sizeof(vis));
cin >> n >> m;
sum=n*m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> a[i][j];
if(a[i][j]=='*')
sum--;
}
}
while(t!=sum){
ans++;
bfs(a[1][1],1,1);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |