#include <iostream>
#include <queue>
using namespace std;
struct node
{
int x;
int y;
};
int n,m;
char mat[4004][4004];
bool vis[4004][4004];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int brojac;
void bfs(queue<node> q1,queue<node> q2,int broj)
{
if(q1.empty())
return;
brojac=broj;
while(!q1.empty())
{
node g=q1.front();
q1.pop();
vis[g.x][g.y]=true;
for(int i=0;i<4;i++)
{
if(g.x+dx[i]<n&&g.x+dx[i]>=0&&g.y+dy[i]<m&&g.y+dy[i]>=0)
{
if(!vis[g.x+dx[i]][g.y+dy[i]]&&mat[g.x+dx[i]][g.y+dy[i]]!='.')
{
if(mat[g.x+dx[i]][g.y+dy[i]]!=mat[g.x][g.y])
{
node g1;
g1.x=g.x+dx[i];
g1.y=g.y+dy[i];
q2.push(g1);
}
else
{
node g1;
g1.x=g.x+dx[i];
g1.y=g.y+dy[i];
q1.push(g1);
}
}
}
}
}
bfs(q2,q1,broj+1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cin>>mat[i][j];
}
queue<node> q1,q2;
node g;
g.x=0;
g.y=0;
q1.push(g);
bfs(q1,q2,1);
cout<<brojac<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2106 ms |
655692 KB |
Time limit exceeded |
2 |
Correct |
2 ms |
655692 KB |
Output is correct |
3 |
Execution timed out |
2070 ms |
655692 KB |
Time limit exceeded |
4 |
Execution timed out |
2100 ms |
655692 KB |
Time limit exceeded |
5 |
Execution timed out |
2106 ms |
655692 KB |
Time limit exceeded |
6 |
Correct |
2 ms |
655692 KB |
Output is correct |
7 |
Execution timed out |
2084 ms |
655692 KB |
Time limit exceeded |
8 |
Execution timed out |
2108 ms |
659840 KB |
Time limit exceeded |
9 |
Correct |
59 ms |
659840 KB |
Output is correct |
10 |
Execution timed out |
2095 ms |
659840 KB |
Time limit exceeded |
11 |
Execution timed out |
2095 ms |
659840 KB |
Time limit exceeded |
12 |
Execution timed out |
2093 ms |
659840 KB |
Time limit exceeded |
13 |
Execution timed out |
2090 ms |
659840 KB |
Time limit exceeded |
14 |
Execution timed out |
2099 ms |
659840 KB |
Time limit exceeded |
15 |
Execution timed out |
2110 ms |
659840 KB |
Time limit exceeded |
16 |
Execution timed out |
2106 ms |
671784 KB |
Time limit exceeded |
17 |
Execution timed out |
2089 ms |
671784 KB |
Time limit exceeded |
18 |
Execution timed out |
2116 ms |
671784 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
671784 KB |
Output is correct |
2 |
Execution timed out |
2094 ms |
671784 KB |
Time limit exceeded |
3 |
Execution timed out |
2097 ms |
671784 KB |
Time limit exceeded |
4 |
Execution timed out |
2100 ms |
671784 KB |
Time limit exceeded |
5 |
Execution timed out |
2103 ms |
1048576 KB |
Time limit exceeded |
6 |
Execution timed out |
2082 ms |
1048576 KB |
Time limit exceeded |
7 |
Correct |
35 ms |
1048576 KB |
Output is correct |
8 |
Correct |
38 ms |
1048576 KB |
Output is correct |
9 |
Execution timed out |
2106 ms |
1048576 KB |
Time limit exceeded |
10 |
Correct |
8 ms |
1048576 KB |
Output is correct |
11 |
Correct |
30 ms |
1048576 KB |
Output is correct |
12 |
Correct |
18 ms |
1048576 KB |
Output is correct |
13 |
Execution timed out |
2084 ms |
1048576 KB |
Time limit exceeded |
14 |
Execution timed out |
2096 ms |
1048576 KB |
Time limit exceeded |
15 |
Correct |
273 ms |
1048576 KB |
Output is correct |
16 |
Execution timed out |
2091 ms |
1048576 KB |
Time limit exceeded |
17 |
Execution timed out |
2088 ms |
1048576 KB |
Time limit exceeded |
18 |
Correct |
944 ms |
1048576 KB |
Output is correct |
19 |
Execution timed out |
2088 ms |
1048576 KB |
Time limit exceeded |
20 |
Execution timed out |
2100 ms |
1048576 KB |
Time limit exceeded |
21 |
Execution timed out |
2099 ms |
1048576 KB |
Time limit exceeded |
22 |
Execution timed out |
2153 ms |
1048576 KB |
Time limit exceeded |
23 |
Execution timed out |
2068 ms |
1048576 KB |
Time limit exceeded |
24 |
Execution timed out |
2157 ms |
1048576 KB |
Time limit exceeded |
25 |
Execution timed out |
2152 ms |
1048576 KB |
Time limit exceeded |
26 |
Execution timed out |
2071 ms |
1048576 KB |
Time limit exceeded |
27 |
Execution timed out |
2095 ms |
1048576 KB |
Time limit exceeded |
28 |
Execution timed out |
2097 ms |
1048576 KB |
Time limit exceeded |
29 |
Execution timed out |
2072 ms |
1048576 KB |
Time limit exceeded |
30 |
Execution timed out |
2083 ms |
1048576 KB |
Time limit exceeded |
31 |
Execution timed out |
2084 ms |
1048576 KB |
Time limit exceeded |
32 |
Execution timed out |
2082 ms |
1048576 KB |
Time limit exceeded |