답안 #634545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634545 2022-08-24T14:43:05 Z Mer123haba456 Zoo (COCI19_zoo) C++14
0 / 110
0 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
#define N lli(2e6)
#define MOD lli(1e9 + 7)
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0);
#define heps(v) v.begin(),v.end()
typedef vector<lli> vlli;
typedef pair<lli,lli> plli;
typedef pair<lli,plli> pplli;
typedef vector<plli> vplli;
typedef vector<pplli> vpplli;
typedef map<lli,lli> mlli;

lli t,n,m,k;

string str;

char mat[2000][2000];

bool vis[2000][2000];

void sifle(lli a,lli b){
    queue<plli> Q;
    Q.push({a,b});
    while(!(Q.empty())){
        plli su = Q.front();
        lli x = su.first;
        lli y = su.second;
        Q.pop();
        if(vis[x][y])
            continue;
        vis[su.first][su.second] = 1;
        bool so = ((y > 0) ? ((!vis[x][y-1]) & (mat[x][y-1] == mat[x][y])) : 0);
        bool sa = ((y < m-1) ? ((!vis[x][y+1]) & (mat[x][y+1] == mat[x][y])) : 0);
        bool yu = ((x > 0) ? ((!vis[x-1][y]) & (mat[x-1][y] == mat[x][y])) : 0);
        bool as = ((x < n-1) ? ((!vis[x+1][y]) & (mat[x+1][y] == mat[x][y])) : 0);
        if(so){
            Q.push({x,y-1});
        }
        if(sa){
            Q.push({x,y+1});
        }
        if(yu){
            Q.push({x-1,y});
        }
        if(as){
            Q.push({x+1,y});
        }
    }
}

int main(){
    fast_io
    cin >> n >> m;
    for(lli i = 0;i<n;i++)
        for(lli j = 0;j<m;j++)
            cin >> mat[i][j];
    lli cev = 0;
    for(lli i = 0;i<n;i++)
        for(lli j = 0;j<m;j++){
            if(!(vis[i][j]) && (mat[i][j] != '*')){
                cev++;
                sifle(i,j);
            }
        }
    cout << cev << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -