Submission #645313

# Submission time Handle Problem Language Result Execution time Memory
645313 2022-09-26T18:03:30 Z Hacv16 Zoo (COCI19_zoo) C++17
0 / 110
1 ms 1236 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 1015;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n"

ll n, m, ans;
char t[MAX][MAX];

void dfs(ll x, ll y){
    char c = t[x][y];
    t[x][y] = '*';

    for(int i = 0; i < 4; i++){
        ll nx = x + dx[i], ny = y + dy[i];
        if(t[nx][ny] == c) dfs(nx, ny);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    cin >> n >> m;

    memset(t, '*', sizeof(t));

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> t[i][j];
        }
    }    

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(t[i][j] != '*') dfs(i, j), ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1236 KB Output isn't correct
2 Halted 0 ms 0 KB -