Submission #222728

#TimeUsernameProblemLanguageResultExecution timeMemory
222728kingfran1907Zoo (COCI19_zoo)C++14
110 / 110
53 ms6400 KiB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;

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

const int maxn = 1010;
const int inf = 0x3f3f3f3f;

int n, m;
char niz[maxn][maxn];
deque< pair<int, int> > q;
int dis[maxn][maxn];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%s", niz+i);

    memset(dis, -1, sizeof dis);
    dis[0][0] = 1;
    q.push_back({0, 0});

    while (!q.empty()) {
        int x = q.front().X;
        int y = q.front().Y;
        q.pop_front();

        for (int i = 0; i < 4; i++) {
            int tx = x + dx[i];
            int ty = y + dy[i];

            if (tx < 0 || tx >= n || ty < 0 || ty >= m) continue;
            if (dis[tx][ty] != -1 || niz[tx][ty] == '*') continue;

            if (niz[tx][ty] == niz[x][y]) {
                dis[tx][ty] = dis[x][y];
                q.push_front({tx, ty});
            } else {
                dis[tx][ty] = dis[x][y] + 1;
                q.push_back({tx, ty});
            }
        }
    }

    int sol = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            sol = max(sol, dis[i][j]);
    printf("%d", sol);
    return 0;
}

Compilation message (stderr)

zoo.cpp: In function 'int main()':
zoo.cpp:21:26: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1010]' [-Wformat=]
         scanf("%s", niz+i);
                     ~~~~~^
zoo.cpp:19: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:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", niz+i);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...