#include <bits/stdc++.h>
using namespace std;
const int tx[4]={0,0,1,-1};
const int ty[4]={1,-1,0,0};
typedef pair<int, int> super;
typedef long long int ll;
#define pu push
bool kt[4005][4005];
int a[4005][4005],n,m,rx,ry;
void bfs(int x,int y)
{
queue<super> p;
p.pu({x,y});
kt[x][y]=true;
ll count1=0;
while (!p.empty())
{
queue <super> p1;
while (!p.empty())
{
x=p.front().first;
y=p.front().second;
p.pop();
for (int i=0;i<4;i++)
{
rx=x+tx[i];
ry=y+ty[i];
if (!kt[rx][ry] && a[rx][ry]!=0)
if (a[rx][ry]==a[x][y])
{
kt[rx][ry]=true;
p.pu({rx,ry});
}
else
{
kt[rx][ry]=true;
p1.pu({rx,ry});
}
}
}
count1++;
p=p1;
}
cout<<count1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("animal.inp","r",stdin);
//freopen("animal.out","w",stdout);
cin>>n>>m;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
char x;
cin>>x;
if (x=='F') a[i][j]=1;
if (x=='R') a[i][j]=2;
}
bfs(1,1);
return 0;
}
Compilation message
tracks.cpp: In function 'void bfs(int, int)':
tracks.cpp:28:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
28 | if (!kt[rx][ry] && a[rx][ry]!=0)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
5300 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
9 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
2900 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
756 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
3 ms |
2388 KB |
Output is correct |
11 |
Correct |
3 ms |
2132 KB |
Output is correct |
12 |
Correct |
8 ms |
3028 KB |
Output is correct |
13 |
Correct |
4 ms |
2900 KB |
Output is correct |
14 |
Correct |
4 ms |
2900 KB |
Output is correct |
15 |
Correct |
16 ms |
5076 KB |
Output is correct |
16 |
Correct |
16 ms |
5276 KB |
Output is correct |
17 |
Correct |
13 ms |
5028 KB |
Output is correct |
18 |
Correct |
8 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
30812 KB |
Output is correct |
2 |
Correct |
65 ms |
13528 KB |
Output is correct |
3 |
Correct |
402 ms |
68276 KB |
Output is correct |
4 |
Correct |
109 ms |
30168 KB |
Output is correct |
5 |
Correct |
484 ms |
49540 KB |
Output is correct |
6 |
Correct |
954 ms |
109440 KB |
Output is correct |
7 |
Correct |
18 ms |
32176 KB |
Output is correct |
8 |
Correct |
17 ms |
30800 KB |
Output is correct |
9 |
Correct |
3 ms |
552 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
18 ms |
31572 KB |
Output is correct |
12 |
Correct |
2 ms |
1620 KB |
Output is correct |
13 |
Correct |
61 ms |
13532 KB |
Output is correct |
14 |
Correct |
34 ms |
9548 KB |
Output is correct |
15 |
Correct |
41 ms |
12132 KB |
Output is correct |
16 |
Correct |
26 ms |
5040 KB |
Output is correct |
17 |
Correct |
170 ms |
26148 KB |
Output is correct |
18 |
Correct |
189 ms |
33080 KB |
Output is correct |
19 |
Correct |
100 ms |
29964 KB |
Output is correct |
20 |
Correct |
95 ms |
22860 KB |
Output is correct |
21 |
Correct |
242 ms |
48708 KB |
Output is correct |
22 |
Correct |
498 ms |
49540 KB |
Output is correct |
23 |
Correct |
317 ms |
39856 KB |
Output is correct |
24 |
Correct |
304 ms |
45944 KB |
Output is correct |
25 |
Correct |
712 ms |
89220 KB |
Output is correct |
26 |
Correct |
516 ms |
76364 KB |
Output is correct |
27 |
Correct |
682 ms |
92360 KB |
Output is correct |
28 |
Correct |
970 ms |
109424 KB |
Output is correct |
29 |
Correct |
956 ms |
106080 KB |
Output is correct |
30 |
Correct |
814 ms |
102236 KB |
Output is correct |
31 |
Correct |
708 ms |
69708 KB |
Output is correct |
32 |
Correct |
707 ms |
90708 KB |
Output is correct |