Submission #783036

# Submission time Handle Problem Language Result Execution time Memory
783036 2023-07-14T14:26:12 Z serifefedartar Zoo (COCI19_zoo) C++17
0 / 110
2 ms 4180 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MAXN 100005

vector<vector<int>> grid;
int R, C;
int vis[1005][1005];
void dfs(int i, int j) {
    vis[i][j] = true;
    vector<int> delRow = {-1, 0, 0, 1};
    vector<int> delCol = {0, -1, 1, 0};
    for (int q = 0; q < 4; q++) {
        int newRow = i + delRow[q];
        int newCol = j + delCol[q];
        if (newRow > R || newRow <= 0 || newCol <= 0 || newCol > C 
            || grid[newRow][newCol] != grid[i][j] || vis[newRow][newCol])
            continue;
        dfs(newRow, newCol);
    }
}

int main() {
    fast
    memset(vis, 0, sizeof(vis));
    cin >> R >> C;
    grid = vector<vector<int>>(R+1, vector<int>(C+1));
    for (int i = 1; i <= R; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= C; j++) {
            if (s[j-1] == '*')
                grid[i][j] = 0;
            else if (s[j-1] == 'T')
                grid[i][j] = 1;
            else
                grid[i][j] = 2;
        }
    }

    ll ans = 0;
    for (int i = 1; i <= R; i++) {
        for (int j = 1; j <= C; j++) {
            if (!vis[i][j] && grid[i][j]) {
                ans++;
                dfs(i, j);
            }
        }
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -