#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e3+10;
typedef pair<int, int> pii;
int n, m;
int ans;
char tab[maxn][maxn];
bool mark[maxn][maxn];
int linha[] = {-1, 1, 0, 0};
int coluna[] = {0, 0, -1, 1};
void bfs(void)
{
deque<pair<pii, int>> dq;
ans = 1, mark[0][0] = 1;
dq.push_front({{0, 0}, 1});
while (!dq.empty())
{
int x = dq.front().first.first;
int y = dq.front().first.second;
int t = dq.front().second;
dq.pop_front();
ans = max(ans, t);
for (int i = 0; i < 4; i++)
{
int a = x+linha[i], b = y+coluna[i];
if (a < 0 || a >= n || b < 0 || b >= m || mark[a][b] || tab[a][b] == '.') continue;
if (tab[a][b] != tab[x][y]) dq.push_back({{a, b}, t+1});
else dq.push_front({{a, b}, t});
mark[a][b] = 1;
}
}
}
int main(void)
{
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf(" %c", &tab[i][j]);
bfs();
printf("%d\n", ans);
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &tab[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
4480 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
768 KB |
Output is correct |
4 |
Correct |
21 ms |
4608 KB |
Output is correct |
5 |
Correct |
9 ms |
2688 KB |
Output is correct |
6 |
Correct |
23 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
768 KB |
Output is correct |
9 |
Correct |
4 ms |
1152 KB |
Output is correct |
10 |
Correct |
10 ms |
2432 KB |
Output is correct |
11 |
Correct |
7 ms |
2048 KB |
Output is correct |
12 |
Correct |
12 ms |
2688 KB |
Output is correct |
13 |
Correct |
9 ms |
2688 KB |
Output is correct |
14 |
Correct |
9 ms |
2688 KB |
Output is correct |
15 |
Correct |
25 ms |
4480 KB |
Output is correct |
16 |
Correct |
24 ms |
4480 KB |
Output is correct |
17 |
Correct |
26 ms |
4352 KB |
Output is correct |
18 |
Correct |
16 ms |
4608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
30456 KB |
Output is correct |
2 |
Correct |
120 ms |
11764 KB |
Output is correct |
3 |
Correct |
1016 ms |
47608 KB |
Output is correct |
4 |
Correct |
242 ms |
18808 KB |
Output is correct |
5 |
Correct |
572 ms |
32772 KB |
Output is correct |
6 |
Correct |
1395 ms |
66944 KB |
Output is correct |
7 |
Correct |
30 ms |
31736 KB |
Output is correct |
8 |
Correct |
28 ms |
30328 KB |
Output is correct |
9 |
Correct |
7 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
30 ms |
31232 KB |
Output is correct |
12 |
Correct |
5 ms |
1536 KB |
Output is correct |
13 |
Correct |
113 ms |
11856 KB |
Output is correct |
14 |
Correct |
82 ms |
8440 KB |
Output is correct |
15 |
Correct |
105 ms |
9208 KB |
Output is correct |
16 |
Correct |
47 ms |
4088 KB |
Output is correct |
17 |
Correct |
313 ms |
20084 KB |
Output is correct |
18 |
Correct |
292 ms |
20028 KB |
Output is correct |
19 |
Correct |
216 ms |
18780 KB |
Output is correct |
20 |
Correct |
229 ms |
17528 KB |
Output is correct |
21 |
Correct |
585 ms |
33944 KB |
Output is correct |
22 |
Correct |
510 ms |
32760 KB |
Output is correct |
23 |
Correct |
544 ms |
27740 KB |
Output is correct |
24 |
Correct |
529 ms |
33656 KB |
Output is correct |
25 |
Correct |
1101 ms |
47572 KB |
Output is correct |
26 |
Correct |
947 ms |
114228 KB |
Output is correct |
27 |
Correct |
1195 ms |
73372 KB |
Output is correct |
28 |
Correct |
1306 ms |
67060 KB |
Output is correct |
29 |
Correct |
1378 ms |
67428 KB |
Output is correct |
30 |
Correct |
1236 ms |
68264 KB |
Output is correct |
31 |
Correct |
976 ms |
36216 KB |
Output is correct |
32 |
Correct |
1182 ms |
70540 KB |
Output is correct |