# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
222728 | kingfran1907 | Zoo (COCI19_zoo) | C++14 | 53 ms | 6400 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>
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |