Submission #871674

# Submission time Handle Problem Language Result Execution time Memory
871674 2023-11-11T09:08:59 Z vjudge1 Zoo (COCI19_zoo) C++17
45 / 110
10 ms 860 KB
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

char matrix[105][105];
bool vis[105][105];

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

#define ONLINE_JUDGE
void solve() {
    int r, c;
    cin >> r >> c;

    int cnt = 0;
    for(int i = 1; i <= r; i++) {
        for(int j = 1; j <= c; j++) {
            cin >> matrix[i][j];
            cnt += (matrix[i][j] != '*');
        }
    }

    auto in = [&](int x, int y) {
        return 1 <= x && x <= r && 1 <= y && y <= c;
    };

    auto ok = [&]() -> int {
        memset(vis, false, sizeof(vis));

        vector <pair <int, int>> vec;
        queue <pair <int, int>> q;
        q.emplace(1, 1);
        while(!q.empty()) {
            auto [x, y] = q.front();
            q.pop();
            if(vis[x][y]) {
                continue;
            }
            vis[x][y] = true;
            vec.emplace_back(x, y);

            for(int i = 0; i < 4; i++) {
                int _x = x + dx[i], _y = y + dy[i];
                if(in(_x, _y) && vis[_x][_y] == false && matrix[_x][_y] == matrix[x][y]) {
                    q.emplace(_x, _y);
                }
            }
        }

        char c = (matrix[1][1] == 'B' ? 'T' : 'B');
        for(auto [a, b] : vec) {
            matrix[a][b] = c;
        }

        return int(vec.size());
    };

    int ans = 1;
    while(ok() < cnt) {
        ans++;
    }

    cout << ans << "\n";
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 7 ms 348 KB Output is correct
12 Correct 10 ms 604 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 7 ms 604 KB Output is correct
11 Correct 7 ms 348 KB Output is correct
12 Correct 10 ms 604 KB Output is correct
13 Correct 5 ms 348 KB Output is correct
14 Correct 5 ms 344 KB Output is correct
15 Correct 6 ms 348 KB Output is correct
16 Runtime error 2 ms 860 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -