#include <bits/stdc++.h>
using namespace std;
int t[4007][4007],vi[4007][4007],n,m;
queue<pair<int,int> > q[3];
void dfs(int x,int y,int k)
{
if(x<0 || y<0 || x>=n || y>=m || vi[x][y]) return;
if(t[x][y]!=k)
{
if(t[x][y]==3-k) q[3-k].push(make_pair(x,y));
return;
}
vi[x][y]=true;
dfs(x-1,y,k);
dfs(x+1,y,k);
dfs(x,y-1,k);
dfs(x,y+1,k);
}
int main()
{
int sol=0;
cin>>n>>m;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
for(int j=0;j<m;j++) t[i][j]=(s[j]=='F'?2:(s[j]=='R'?1:0));
}
q[t[0][0]].push(make_pair(0,0));
for(int i=0;i<100000;i++)
{
if(!q[1].empty())
{
sol++;
while(!q[1].empty())
{
if(!vi[q[1].front().first][q[1].front().second]) dfs(q[1].front().first,q[1].front().second,1);
q[1].pop();
}
}
if(!q[2].empty())
{
sol++;
while(!q[2].empty())
{
if(!vi[q[2].front().first][q[2].front().second]) dfs(q[2].front().first,q[2].front().second,2);
q[2].pop();
}
}
}
printf("%d",sol);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6648 KB |
Output is correct |
2 |
Correct |
2 ms |
6648 KB |
Output is correct |
3 |
Correct |
3 ms |
6648 KB |
Output is correct |
4 |
Correct |
19 ms |
7000 KB |
Output is correct |
5 |
Correct |
9 ms |
7000 KB |
Output is correct |
6 |
Correct |
2 ms |
7000 KB |
Output is correct |
7 |
Correct |
3 ms |
7000 KB |
Output is correct |
8 |
Correct |
3 ms |
7000 KB |
Output is correct |
9 |
Correct |
3 ms |
7000 KB |
Output is correct |
10 |
Correct |
9 ms |
7000 KB |
Output is correct |
11 |
Correct |
6 ms |
7000 KB |
Output is correct |
12 |
Correct |
14 ms |
7000 KB |
Output is correct |
13 |
Correct |
11 ms |
7000 KB |
Output is correct |
14 |
Correct |
9 ms |
7000 KB |
Output is correct |
15 |
Correct |
31 ms |
7600 KB |
Output is correct |
16 |
Correct |
33 ms |
7856 KB |
Output is correct |
17 |
Correct |
24 ms |
7856 KB |
Output is correct |
18 |
Correct |
18 ms |
8328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
33600 KB |
Output is correct |
2 |
Correct |
138 ms |
33600 KB |
Output is correct |
3 |
Incorrect |
678 ms |
95464 KB |
Output isn't correct |
4 |
Correct |
228 ms |
95464 KB |
Output is correct |
5 |
Incorrect |
363 ms |
95464 KB |
Output isn't correct |
6 |
Correct |
1574 ms |
185496 KB |
Output is correct |
7 |
Correct |
36 ms |
185496 KB |
Output is correct |
8 |
Correct |
34 ms |
185496 KB |
Output is correct |
9 |
Correct |
7 ms |
185496 KB |
Output is correct |
10 |
Correct |
4 ms |
185496 KB |
Output is correct |
11 |
Correct |
32 ms |
185496 KB |
Output is correct |
12 |
Correct |
4 ms |
185496 KB |
Output is correct |
13 |
Correct |
153 ms |
185496 KB |
Output is correct |
14 |
Correct |
83 ms |
185496 KB |
Output is correct |
15 |
Correct |
86 ms |
185496 KB |
Output is correct |
16 |
Correct |
54 ms |
185496 KB |
Output is correct |
17 |
Correct |
374 ms |
185496 KB |
Output is correct |
18 |
Incorrect |
233 ms |
185496 KB |
Output isn't correct |
19 |
Correct |
238 ms |
185496 KB |
Output is correct |
20 |
Correct |
195 ms |
185496 KB |
Output is correct |
21 |
Incorrect |
482 ms |
185496 KB |
Output isn't correct |
22 |
Incorrect |
376 ms |
185496 KB |
Output isn't correct |
23 |
Correct |
646 ms |
185496 KB |
Output is correct |
24 |
Incorrect |
422 ms |
185496 KB |
Output isn't correct |
25 |
Incorrect |
709 ms |
185496 KB |
Output isn't correct |
26 |
Correct |
1965 ms |
692768 KB |
Output is correct |
27 |
Correct |
1536 ms |
692768 KB |
Output is correct |
28 |
Correct |
1544 ms |
692768 KB |
Output is correct |
29 |
Correct |
1479 ms |
692768 KB |
Output is correct |
30 |
Correct |
1500 ms |
692768 KB |
Output is correct |
31 |
Correct |
1224 ms |
692768 KB |
Output is correct |
32 |
Correct |
1678 ms |
692768 KB |
Output is correct |