답안 #725462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725462 2023-04-17T13:25:35 Z kerem Zoo (COCI19_zoo) C++14
0 / 110
4 ms 8148 KB
#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];
void bfs(char c,int x,int y){
    queue<pair<int,int>> q;
    q.push({x,y});
    while(!q.empty()){
        x=q.front().fir;
        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});
    }
    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];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(vis[i][j]==1 or a[i][j]=='*') continue;
            ans++;
            bfs(a[i][j],i,j);
        }
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8148 KB Output isn't correct
2 Halted 0 ms 0 KB -