#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define f first
#define s second
const int MAX_W = 4005;
int N, M;
char L[MAX_W][MAX_W];
int dep[MAX_W][MAX_W];
bool vis[MAX_W][MAX_W];
pii Move[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for (int i = 0; i <= N + 1; i++)
{
for (int j = 0; j < M + 1; j++)
{
if (i == 0 || j == 0 || i == N + 1 || j == M + 1)
{
L[i][j] = '.';
continue;
}
cin >> L[i][j];
}
}
/*for (int i = 0; i <= N + 1; i++)
{
for (int j = 0; j < M + 1; j++)
{
cout << L[i][j];
}
cout << '\n';
}*/
//cout << '\n';
deque<pii> q;
q.push_front({1, 1});
int ans = 1;
dep[1][1] = 1;
vis[1][1] = true;
while (!q.empty())
{
//cout << "size = " << q.size() << '\n';
pii pos = q.front();
//cout << "pos = {" << pos.f << ", " << pos.s << "}\n";
//cout << "val: " << L[pos.f][pos.s] << '\n';
q.pop_front();
pii newpos;
for (int i = 0; i < 4; i++)
{
newpos = {pos.f + Move[i].f, pos.s + Move[i].s};
if (vis[newpos.f][newpos.s] || (L[newpos.f][newpos.s] != 'F' && L[newpos.f][newpos.s] != 'R')) continue;
vis[newpos.f][newpos.s] = true;
if (L[newpos.f][newpos.s] == L[pos.f][pos.s])
{
dep[newpos.f][newpos.s] = dep[pos.f][pos.s];
q.push_front(newpos);
}
else
{
dep[newpos.f][newpos.s] = dep[pos.f][pos.s] + 1;
ans = max(ans, dep[pos.f][pos.s] + 1);
q.push_back(newpos);
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
7124 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
8 ms |
6900 KB |
Output is correct |
5 |
Correct |
4 ms |
3924 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
852 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
1492 KB |
Output is correct |
10 |
Correct |
4 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
2900 KB |
Output is correct |
12 |
Correct |
7 ms |
4128 KB |
Output is correct |
13 |
Correct |
5 ms |
3924 KB |
Output is correct |
14 |
Correct |
4 ms |
3924 KB |
Output is correct |
15 |
Correct |
14 ms |
7012 KB |
Output is correct |
16 |
Correct |
13 ms |
7124 KB |
Output is correct |
17 |
Correct |
13 ms |
6868 KB |
Output is correct |
18 |
Correct |
9 ms |
6996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
45680 KB |
Output is correct |
2 |
Correct |
53 ms |
19212 KB |
Output is correct |
3 |
Correct |
367 ms |
86816 KB |
Output is correct |
4 |
Correct |
97 ms |
38988 KB |
Output is correct |
5 |
Correct |
206 ms |
63440 KB |
Output is correct |
6 |
Correct |
697 ms |
121876 KB |
Output is correct |
7 |
Correct |
27 ms |
47828 KB |
Output is correct |
8 |
Correct |
29 ms |
45652 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
28 ms |
46960 KB |
Output is correct |
12 |
Correct |
2 ms |
2132 KB |
Output is correct |
13 |
Correct |
58 ms |
19112 KB |
Output is correct |
14 |
Correct |
41 ms |
13260 KB |
Output is correct |
15 |
Correct |
35 ms |
16260 KB |
Output is correct |
16 |
Correct |
24 ms |
6664 KB |
Output is correct |
17 |
Correct |
134 ms |
35572 KB |
Output is correct |
18 |
Correct |
125 ms |
42388 KB |
Output is correct |
19 |
Correct |
115 ms |
38860 KB |
Output is correct |
20 |
Correct |
86 ms |
31192 KB |
Output is correct |
21 |
Correct |
231 ms |
63016 KB |
Output is correct |
22 |
Correct |
208 ms |
63612 KB |
Output is correct |
23 |
Correct |
268 ms |
51864 KB |
Output is correct |
24 |
Correct |
200 ms |
60236 KB |
Output is correct |
25 |
Correct |
438 ms |
107920 KB |
Output is correct |
26 |
Correct |
371 ms |
142940 KB |
Output is correct |
27 |
Correct |
498 ms |
142524 KB |
Output is correct |
28 |
Correct |
573 ms |
121864 KB |
Output is correct |
29 |
Correct |
579 ms |
119652 KB |
Output is correct |
30 |
Correct |
518 ms |
124880 KB |
Output is correct |
31 |
Correct |
467 ms |
84348 KB |
Output is correct |
32 |
Correct |
449 ms |
129744 KB |
Output is correct |