#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
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 |
1 |
Correct |
8 ms |
7512 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
5 ms |
7260 KB |
Output is correct |
5 |
Correct |
2 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
4504 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
5468 KB |
Output is correct |
11 |
Correct |
2 ms |
5468 KB |
Output is correct |
12 |
Correct |
4 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5724 KB |
Output is correct |
14 |
Correct |
2 ms |
5720 KB |
Output is correct |
15 |
Correct |
7 ms |
7260 KB |
Output is correct |
16 |
Correct |
8 ms |
7372 KB |
Output is correct |
17 |
Correct |
7 ms |
7224 KB |
Output is correct |
18 |
Correct |
5 ms |
7260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
32348 KB |
Output is correct |
2 |
Correct |
27 ms |
18056 KB |
Output is correct |
3 |
Correct |
137 ms |
73872 KB |
Output is correct |
4 |
Correct |
41 ms |
35220 KB |
Output is correct |
5 |
Correct |
82 ms |
55488 KB |
Output is correct |
6 |
Correct |
406 ms |
108684 KB |
Output is correct |
7 |
Correct |
8 ms |
32856 KB |
Output is correct |
8 |
Correct |
8 ms |
32344 KB |
Output is correct |
9 |
Correct |
2 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2508 KB |
Output is correct |
11 |
Correct |
8 ms |
32704 KB |
Output is correct |
12 |
Correct |
1 ms |
4952 KB |
Output is correct |
13 |
Correct |
30 ms |
18260 KB |
Output is correct |
14 |
Correct |
16 ms |
12884 KB |
Output is correct |
15 |
Correct |
12 ms |
15196 KB |
Output is correct |
16 |
Correct |
13 ms |
8028 KB |
Output is correct |
17 |
Correct |
67 ms |
30900 KB |
Output is correct |
18 |
Correct |
44 ms |
37708 KB |
Output is correct |
19 |
Correct |
46 ms |
35712 KB |
Output is correct |
20 |
Correct |
36 ms |
28752 KB |
Output is correct |
21 |
Correct |
86 ms |
54340 KB |
Output is correct |
22 |
Correct |
82 ms |
55632 KB |
Output is correct |
23 |
Correct |
126 ms |
45900 KB |
Output is correct |
24 |
Correct |
76 ms |
51536 KB |
Output is correct |
25 |
Correct |
235 ms |
94216 KB |
Output is correct |
26 |
Correct |
334 ms |
133296 KB |
Output is correct |
27 |
Correct |
322 ms |
120060 KB |
Output is correct |
28 |
Correct |
393 ms |
108464 KB |
Output is correct |
29 |
Correct |
390 ms |
106300 KB |
Output is correct |
30 |
Correct |
361 ms |
111300 KB |
Output is correct |
31 |
Correct |
298 ms |
76944 KB |
Output is correct |
32 |
Correct |
324 ms |
114108 KB |
Output is correct |