#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
char g[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>g[i][j];
}
}
vector<pair<pi,bool> > adj[n][m];
int vis[n][m];
memset(vis,-1,sizeof vis);
int dx[]={0,0,-1,1};
int dy[]={-1,1,0,0};
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
for(int d=0;d<4;d++)
{
int ni=i+dx[d],nj=j+dy[d];
if(ni<n && ni>=0 && nj<m && nj>=0 && g[i][j]!='.' && g[ni][nj]!='.'){
adj[i][j].pb({{ni,nj},(g[i][j]==g[ni][nj])});
}
}
}
}
deque<pi> dq;
dq.pb({0,0});vis[0][0]=0;
int ans=0;
while(!dq.empty()){
int i=dq.front().F,j=dq.front().S;
dq.pop_back();
for(auto p:adj[i][j])
{
int ni=p.F.F,nj=p.F.S,w=p.S;
if(vis[ni][nj]!=-1)continue;
vis[ni][nj]=w+vis[i][j];
ans=max(ans,vis[ni][nj]);
if(w)dq.pb({ni,nj});
else dq.push_front({ni,nj});
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
22096 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
756 KB |
Output isn't correct |
4 |
Incorrect |
21 ms |
14416 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
3652 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
3932 KB |
Output isn't correct |
12 |
Incorrect |
11 ms |
8028 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
3676 KB |
Output isn't correct |
15 |
Incorrect |
27 ms |
18520 KB |
Output isn't correct |
16 |
Incorrect |
32 ms |
22108 KB |
Output isn't correct |
17 |
Incorrect |
20 ms |
12880 KB |
Output isn't correct |
18 |
Incorrect |
24 ms |
14428 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2140 KB |
Output isn't correct |
2 |
Incorrect |
111 ms |
82488 KB |
Output isn't correct |
3 |
Incorrect |
814 ms |
656024 KB |
Output isn't correct |
4 |
Incorrect |
189 ms |
133204 KB |
Output isn't correct |
5 |
Incorrect |
651 ms |
405432 KB |
Output isn't correct |
6 |
Runtime error |
1354 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Incorrect |
3 ms |
2140 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
2344 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
3672 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
1628 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
2004 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1460 KB |
Output isn't correct |
13 |
Incorrect |
113 ms |
82368 KB |
Output isn't correct |
14 |
Incorrect |
67 ms |
47952 KB |
Output isn't correct |
15 |
Incorrect |
56 ms |
38484 KB |
Output isn't correct |
16 |
Incorrect |
56 ms |
39764 KB |
Output isn't correct |
17 |
Incorrect |
290 ms |
209944 KB |
Output isn't correct |
18 |
Incorrect |
226 ms |
152280 KB |
Output isn't correct |
19 |
Incorrect |
189 ms |
133200 KB |
Output isn't correct |
20 |
Incorrect |
194 ms |
145444 KB |
Output isn't correct |
21 |
Incorrect |
503 ms |
385076 KB |
Output isn't correct |
22 |
Incorrect |
655 ms |
405516 KB |
Output isn't correct |
23 |
Incorrect |
571 ms |
408340 KB |
Output isn't correct |
24 |
Incorrect |
512 ms |
361712 KB |
Output isn't correct |
25 |
Incorrect |
906 ms |
612692 KB |
Output isn't correct |
26 |
Runtime error |
1397 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
1314 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
1335 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
1329 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
1326 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Incorrect |
1350 ms |
940024 KB |
Output isn't correct |
32 |
Runtime error |
1392 ms |
1048576 KB |
Execution killed with signal 9 |