답안 #445124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445124 2021-07-16T13:58:03 Z Wasif_Jamil Zoo (COCI19_zoo) C++14
0 / 110
4 ms 8140 KB
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29]
 
#include<bits/stdc++.h>
using namespace std; 
vector<vector<int>>v(1001, vector<int>(1001)), vis(1001, vector<int>(1001));
int n, m;
vector<pair<int,int>> dx = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
void dfs(int i, int j, int color){
    if(i < 1 or i > n or j < 1 or j > m){
        return;
    }
    if(vis[i][j]){
        return;
    }
    if(v[i][j] != color){
        return;
    }
    vis[i][j] = 1;
    for(pair<int,int> u : dx){
        dfs(i+u.first, j+u.second, color);
    }
}

int main(){
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            char x; cin >> x;
            if(x == 'T'){
                v[i][j] = 1;
            }
            if(x == 'B'){
                v[i][j] = 2;
            }
        }
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(vis[i][j] == 0 and v[i][j]){
                ans++;
                dfs(i, j, v[i][j]);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -