Submission #1356672

#TimeUsernameProblemLanguageResultExecution timeMemory
1356672po_rag526Tracks in the Snow (BOI13_tracks)C++17
2.19 / 100
269 ms31856 KiB
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define int ll

int dx[]={1, -1, 0, 0}, dy[]={0, 0, 1, -1};
char a[4005][4005];
bool flag[4005][4005];

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++)for(int j=1; j<=m; j++){
        cin >> a[i][j];
    }
    int ans=0, skibidi=0;
    for(int i=1; i<=n; i++)for(int j=1; j<=m; j++){
        if(a[i][j]!=a[1][1])skibidi=1;
        if(!flag[i][j] && a[i][j]==a[1][1]){
            ans++;
            queue<pair<int, int>> q;
            q.push({i, j});
            flag[i][j]=1;
            while(!q.empty()){
                auto [x,y]=q.front();
                q.pop();

                for(int k=0; k<4; k++){
                    int X=x+dx[k], Y=y+dy[k];
                    if(X>=1 && Y>=1 && X<=n && Y<=m && a[X][Y]==a[1][1] && !flag[X][Y]){
                        flag[X][Y]=1;
                        q.push({X, Y});
                    }
                }
            }
        }
    }
    cout << ans+skibidi;
    return 0;
}
/*
5 8
FFR.....
.FRRR...
.FFFFF..
..RRRFFR
.....FFF

2
*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...