Submission #725488

#TimeUsernameProblemLanguageResultExecution timeMemory
725488keremZoo (COCI19_zoo)C++14
110 / 110
108 ms10240 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];
char a[1005][1005];
queue<pair<int,int>> kalan;
void bfs(char c,char c1){
    queue<pair<int,int>> q;
    while(!kalan.empty()){
        q.push({kalan.front().fir,kalan.front().sec});
        kalan.pop();
    }
    while(!q.empty()){
        int x=q.front().fir;
        int y=q.front().sec;
        q.pop();
        if(vis[x][y]==1) continue;
        vis[x][y]=1;
        if(a[x+1][y]==c and vis[x+1][y]!=1)
            q.push({x+1,y});
        if(a[x-1][y]==c and vis[x-1][y]!=1)
            q.push({x-1,y});
        if(a[x][y+1]==c and vis[x][y+1]!=1)
            q.push({x,y+1});
        if(a[x][y-1]==c and vis[x][y-1]!=1)
            q.push({x,y-1});

        if(a[x+1][y]==c1 and vis[x+1][y]!=1)
            kalan.push({x+1,y});
        if(a[x-1][y]==c1 and vis[x-1][y]!=1)
            kalan.push({x-1,y});
        if(a[x][y+1]==c1 and vis[x][y+1]!=1)
            kalan.push({x,y+1});
        if(a[x][y-1]==c1 and vis[x][y-1]!=1)
            kalan.push({x,y-1});
    }
    return;
}
int32_t main(){
    int ans=0;
    memset(vis,0,sizeof(vis));
    cin >> n >> m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin >> a[i][j];
    kalan.push({1,1});
    char c=a[1][1],c1;
    if(c=='B') c1='T';
    else c1='B';
    while(!kalan.empty()){
        ans++;
        bfs(c,c1);
        char temp=c;
        c=c1;
        c1=temp;
    }
    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...