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;
using pii = pair<int, int>;
const int N = 4005, cd[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int n, m, d[N][N], mx = 1;
char c[N][N];
deque<pii> q;
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", c[i]);
d[0][0] = 1;
q.emplace_back(0, 0);
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop_front();
mx = max(mx, d[x][y]);
for (int i = 0; i < 4; i++) {
int nx = x + cd[i][0], ny = y + cd[i][1];
if (nx < 0 || nx >= n || ny < 0 || ny >= m || c[nx][ny] == '.' || d[nx][ny]) continue;
if (c[nx][ny] == c[x][y]) d[nx][ny] = d[x][y], q.emplace_front(nx, ny);
else d[nx][ny] = d[x][y] + 1, q.emplace_back(nx, ny);
}
}
printf("%d", mx);
}
Compilation message (stderr)
tracks.cpp: In function 'int main()':
tracks.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | for (int i = 0; i < n; i++) scanf("%s", c[i]);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |