답안 #199485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199485 2020-02-01T14:53:40 Z SamAnd Zoo (COCI19_zoo) C++17
110 / 110
43 ms 2424 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);
                    }
                }
            }
        }
        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

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]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 380 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 5 ms 380 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 380 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 14 ms 2296 KB Output is correct
17 Correct 14 ms 2296 KB Output is correct
18 Correct 13 ms 2296 KB Output is correct
19 Correct 15 ms 2424 KB Output is correct
20 Correct 13 ms 2424 KB Output is correct
21 Correct 40 ms 2168 KB Output is correct
22 Correct 40 ms 2168 KB Output is correct
23 Correct 41 ms 2168 KB Output is correct
24 Correct 42 ms 2296 KB Output is correct
25 Correct 43 ms 2320 KB Output is correct
26 Correct 39 ms 2168 KB Output is correct
27 Correct 40 ms 2168 KB Output is correct
28 Correct 39 ms 2168 KB Output is correct
29 Correct 41 ms 2296 KB Output is correct
30 Correct 39 ms 2296 KB Output is correct