Submission #199484

# Submission time Handle Problem Language Result Execution time Memory
199484 2020-02-01T14:52:10 Z SamAnd Zoo (COCI19_zoo) C++17
0 / 110
2000 ms 376 KB
#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);
                    }
                }
            }
        }
        q = qq;
        while (!qq.empty())
            qq.pop();
        swap(z, hz);
    }
    printf("%d\n", ans);
    return 0;
}

Compilation message

zoo.cpp: In function 'int main()':
zoo.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
zoo.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", a[i]);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Execution timed out 2085 ms 376 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Execution timed out 2085 ms 376 KB Time limit exceeded
5 Halted 0 ms 0 KB -