| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 199485 | SamAnd | Zoo (COCI19_zoo) | C++17 | 43 ms | 2424 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};
struct ban
{
    int x, y;
    ban(){}
    ban(int x, int y)
    {
        this->x = x;
        this->y = y;
    }
};
int n, m;
char a[N][N];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf(" %s", a[i]);
    if (a[0][0] == '*')
    {
        printf("0\n");
        return 0;
    }
    int ans = 0;
    char z = a[0][0];
    char hz;
    if (z == 'B')
        hz = 'T';
    else
        hz = 'B';
    queue<ban> q, qq;
    q.push(ban(0, 0));
    a[0][0] = 'X';
    while (1)
    {
        if (q.empty())
            break;
        ++ans;
        while (!q.empty())
        {
            ban t = q.front();
            q.pop();
            for (int i = 0; i < 4; ++i)
            {
                ban h = t;
                h.x += xx[i];
                h.y += yy[i];
                if (h.x >= 0 && h.x < n && h.y >= 0 && h.y < m)
                {
                    if (a[h.x][h.y] == z)
                    {
                        a[h.x][h.y] = 'X';
                        q.push(h);
                    }
                    else if (a[h.x][h.y] == hz)
                    {
                        qq.push(h);
                    }
                }
            }
        }
        while (!qq.empty())
        {
            ban t = qq.front();
            a[t.x][t.y] = 'X';
            q.push(t);
            qq.pop();
        }
        swap(z, hz);
    }
    printf("%d\n", ans);
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
