Submission #725472

#TimeUsernameProblemLanguageResultExecution timeMemory
725472keremZoo (COCI19_zoo)C++14
45 / 110
2095 ms10084 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...